Lesson 39 of 55
15 mins readPython Indexed Access Types
In Plain English
Indexed access types (also called lookup types) allow you to query a member type from an existing type using bracket notation.
Core Rules to Remember

Type[Key]: Extracts the property type of Key from Type.

Array Element Access: Type[number] extracts the element type of an array or tuple.
Live Interactive Example
Hit Run Code to see it liveQuerying Nested Property Types
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Output Console
Click "Run Code" to view the rendered output.
How it works: ComplexService["endpoints"] extracts the nested object shape, and [number] extracts the element type.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Extract User Address Type
Define interface Account { id: number; address: { city: string; zip: string } }.
Create type Address = Account["address"].
Create const addr: Address = { city: "San Francisco", zip: "94107" } and print `${addr.city} ${addr.zip}`.
1
2
3
4
5
6
7
8
9
10
11
12
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.