I want to create a typed array in Javascript.
For example when I create a class like this:
export default class AnalyticData {
constructor(collection = []) {
return collection.map((item) => new AnalyticDatum(item))
}
}
and after I make myData = new AnalyticData() the type of myData is Array and not AnalyticData
Does anyone know how to make sure that I have a AnalyticData type and not an Array?
I ask this because in my vue component I have this:
props: {
analyticData: {
type: AnalyticData,
required: true,
},
},
And so this warning :
[Vue warn]: Invalid prop: type check failed for prop "analyticData". Expected AnalyticData, got Array
Does anybody know how to create a typed Array in JS ?
AnalyticDatatype foranalyticDataprop ?returnanything from your constructor. That is causingmyDatabeing an array instead of aAnalyticDatainstance. I don't have a clue what you actually want to do with the result of that.map()though. Possibly you want to assign it to a property instead.