capypad
0 day streak
typescript / beginner
Snippet

Tuple Types

A tuple is a specialized array where you know exactly how many elements it contains and which types are at specific positions.

snippet.ts
typescript
1
2
let response: [number, string];
response = [200, "Success"];
Breakdown
1
let response: [number, string];
Defines a tuple that must have exactly two elements: a number followed by a string.
2
response = [200, "Success"];
Initializes the tuple with values that match the defined schema.