Arrays coercion
class BooksCollection extends Array {}
const Library = attributes({
books: {
type: BooksCollection,
itemType: String,
},
users: {
type: Array,
itemType: String,
},
})(class Library {});
const libraryOne = new Library({
books: ['Brave New World'],
users: ['John', 1],
});
libraryOne.books; // BooksCollection ['Brave New World'] => coerced the array to BooksCollection
libraryOne.users; // ['John', '1'] => new instance of Array with coerced itemsObservations
Last updated