Lesson 05 of 55
9 mins readPython Typed Arrays, ReadonlyArray & Fixed Tuples
In Plain English
TypeScript supports typed arrays (`number[]` or `Array<number>`), immutable arrays (`readonly string[]`), and fixed-length typed tuples with specific element types (`[string, number]`).
Deep Dive: How It Works
Array Syntax: `number[]` or generic `Array<number>`.
ReadonlyArray<T>: Prevents mutating operations like `push`, `pop`, or index assignments.
Tuples: `[string, number, boolean]` specifies exact length and positional types.
Labeled Tuples: `[name: string, age: number]` enhances IDE autocompletion and documentation.
Core Rules to Remember

Tuples Guarantee Length & Types: `[x: number, y: number]` enforces exact pair structures.

readonly Modifiers: Protects arrays from unintended mutations across function calls.
Live Interactive Example
Hit Run Code to see it liveTyped Tuples and Readonly Arrays
Python 3.12
1
2
3
4
5
6
7
8
9
Output Console
Click "Run Code" to view the rendered output.
How it works: GeoPoint enforced an exact 3-element tuple structure.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Define HTTP Response Tuple
Define `type HttpResponse = [status: number, message: string];`
Declare `const res: HttpResponse = [200, "OK"];`
Log `"Response: " + res[0] + " " + res[1]`.
1
2
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.