O'Reilly logo

Cross-platform Desktop Application Development: Electron, Node, NW.js, and React by Dmitry Sheiko

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Array, plain objects, and indexable types

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required