Array Type Annotations in TypeScript

By Hemanta Sundaray on 2023-02-15

type[ ]

The simplest way to type annotate an array is by putting square brackets ([]) after the element type.

For example, suppose we have an array of strings:

let brands = ["Kia", "Toyota", "Honda"]

We can annotate it like this:

let brands: string[] = ["Kia", "Toyota", "Honda"]

Array<type>

An alternative method is to use the Array<type> syntax.

let brands: Array<string> = ["Kia", "Toyota", "Honda"]

Join the Newsletter