Issue
I'm having trouble deciphering a TypeScript syntax I found within an interface declaration here.
interface FormattingOptions {
tabSize: number;
insertSpaces: boolean;
[key: string]: boolean | number | string;
}
Can someone explain me the third parameter of this interface? The one containing [key: string] ...? How is this type of syntax called?
Solution
It's an index signature. It means that besides the known properties of the interface, any other properties of type boolean, number or string can be present
interface FormattingOptions {
tabSize: number;
insertSpaces: boolean;
[key: string]: boolean | number | string;
}
let f: FormattingOptions = {
tabSize: 1,
insertSpaces: true,
other: '' // witout the index signature this would be invalid.
};
Answered By - Titian Cernicova-Dragomir
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.