Skip to main content

ArrayTS Extended Type for Array

CAPITAL Array NOT array

default JS: typeof [] === "object"

List

Array with sequence of same Type elements & variable length

Tuple

Array with fixed length & fixed element Type

TS annotate the following array

let colors = ["red", "green", "blue"]

let colors: string[] = ["red", "green", "blue"]

TS annotate the following array

let numbers = [1, 2, 3]

let numbers: number[] = [1, 2, 3]

Add 2 types of Date and string to an array:

const dates_array = [new Date(), "2030-10-10"]

const dates_array: ( Date | string )[] = [new Date(), "2030-10-10"]

const dates_array: (Date | string)[] = [new Date(), "2030-10-10"];

References

  1. ListArray with sequence of same Type elements & variable length

  2. TupleArray with fixed length & fixed element Type

  3. Typed [Rest Parameter](rest-parameter)TS Syntax for Rest Parameter which must always be of Type Array