简体   繁体   中英

Is there a way to define a Class in JS Array?

Can i define Class of objects that are stored in array? Similar to

ArrayList<? extends E> array = new ArrayList<?>()

Im trying to do something like this:

let myArray = new Array(SomeClass)

but it's only pushing a class as first object, funny my IDE shows me, that objects in this Array are of SomeClass 显示数组类型的图像

Just add the type definition to the variable.

let myArray: SomeClass[] = [];

TypeScript Playground for this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM