I'd like to wrap the generic Array in typescript. We have code as below:
_bindings: Array<BindingDescription>;
What I want is to have a wrapper around Array so I can use
_bindings: BindingDescriptionCollection;
I'm trying to wrap it as below:
export class BindingDescriptionCollection implements Array<BindingDescription> {}
But it need to implements all the functions and properties in Array.
Is there any easier way?
Are you looking to add additional functionality or simply just use a cleaner name? If it's the latter, you can use a type alias :
type BindingDescriptionCollection = Array<BindingDescription>;
But it need to implements all the functions and properties in Array. Is there any easier way?
You can use extend
to inherit the functionality:
interface BindingDescription{}
class BindingDescriptionCollection extends Array<BindingDescription> {}
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.