Can someone please tell me what the
[index : string] : IFoo
means in
export interface IBar {
[index : string] : IFoo;
}
export interface IFoo {
CharacterName: string;
DisplayName: string;
}
I looked through the Typescript Revealed book and found nothing on that notation. Is it supposed to be a collection of objects that implement IFoo? Thanks.
It is used to show the type of the result when an instance of the interface is indexed. When elements of type IBar are indexed by a string i.e [someString]
the result will be of type IFoo.
e.g:
export interface IBar {
[index : string] : IFoo;
}
export interface IFoo {
CharacterName: string;
DisplayName: string;
}
var x:IBar;
var y=x['asdf']; // Same as var y:IFoo = x['asdf']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With