Arrays coercion
It's also possible to coerce values to Array
or some other class that extends Array
. On these circumstances Structure will use the itemType
value of the attribute definition on the schema to coerce the items as well. Note that, when coercing arrays, it'll always create a new instance of the type and then push each item of the passed value to the new instance:
The passed raw value have to be non-null and have a length
attribute or implement the Symbol.iterator
method, otherwise it'll fail to coerce and throw a TypeError
.
Observations
Structure only does array items coercion during instantiation, so mutating an array (using push, for example) won't coerce the new item:
Last updated