Open divyanshu-rawat opened 4 years ago
String or Object would probably be the best 2 choices depending on how you want to use it.
I know that but this Question is not about using them, it's about the types polymer supports.
Hi @divyanshu-rawat. The type
key on a Polymer property is sometimes confusing because it serves a very different purpose than a TypeScript type.
The property type is used only when converting an attribute value to a property value. The process is described here:
https://polymer-library.polymer-project.org/3.0/docs/devguide/properties#attribute-deserialization
You can use any type you want in the properties
object. For example, you could use a constructor for your own type (MyCustomType
) or a string ('array-or-date'
).
If Polymer doesn't recognize the type, and you don't specify a custom deserializer, the attribute value is used unmodified (this is the same behavior as type: String
). The list of built-in types is listed in the docs, but it's short enough to repeat here: it's Boolean, Date, Number, String, Array and Object.
In the case where your property could take many different types, you probably want to use the TypeScript 'any'. If you want to be able to initialize it from an attribute, Object
is often a good choice--it'll first try to parse it as a JSON string; if that fails, it treats the attribute value as a string.
If you need more complicated deserialization logic, you can write a custom deserializer.
@arthurevans sounds good 👍 , as far as I have concluded polymer
has no native support for any type, we have to createcustom type
.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
So, I am basically a frontend developer from Angular, React background and have started to work with Polymer, since 1 month, Just like all JS frameworks and libraries, Polymer 3.0 also utilizes ES6.
So, for instance if I have a
XCustom polymer class
having a propertyuser
declared on it followed by its type.So, if we talk about TS(typescript) then if we declare any property in a class and if we don't know its type then we just write any. like this
user:any .
What about
any
property type in polymer ?