typescript / beginner
Snippet
Working with Tuples
A tuple is a TypeScript type that allows you to express an array with a fixed number of elements whose types are known, but need not be the same.
snippet.ts
1
2
3
const employee: [number, string, boolean] = [1, "Jane Doe", true];const id = employee[0];const name = employee[1];
Breakdown
1
const employee: [number, string, boolean]
Defines a tuple that must contain exactly a number, a string, and a boolean in that order.
2
[1, "Jane Doe", true]
Initializes the tuple with values matching the defined types.