Array type interfaces

We can also define an interface for array types. We can specify the data type for the index array and the data type to the array item, as shown:

interface CutomerNameArray { 
[index: number]: string;
}
let customerNameList: CutomerNameArray;
customerNameList = ["Rajesh", "Gunasundaram"];

TypeScript supports two types of index, namely number, and string. This array type interface also enforces that the return type of the array should match the declaration.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset