July 2017
Intermediate to advanced
300 pages
5h 43m
English
Well, I believe, with primitive types, it's more or less clear, but what about the others, for example, arrays? By combining basic type with [], we define an array type:
let arr: string[];
Here, we declare the variable arr that is an array of string. We can achieve the same with the following syntax:
let arr: Array<string>;
Alternatively, we can do it with interface:
interface StringArray {
[ index: number ]: string;
}
const arr: StringArray = [ "one", "two", "tree" ];
While declaring the StringArray interface by using the so-called index signature, we set constraints on the type structure. It accepts numeric indexes and string values. In other words, it's a string array. We can go further and ...
Read now
Unlock full access