Lesson 38 of 55
15 mins readPython The typeof Type Operator
In Plain English
TypeScript adds a typeof operator you can use in a type context to refer to the type of an existing variable, function, or object value without duplicate interface definitions.
Core Rules to Remember

Type Context typeof: Derives types directly from runtime constants and configuration objects.

DRY Principle: Eliminates redundant interface definitions for static constants.
Live Interactive Example
Hit Run Code to see it liveDeriving Types from Runtime Constants
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Output Console
Click "Run Code" to view the rendered output.
How it works: AppTheme captures the exact nested structure of defaultTheme.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Derive Action Type from Object
Define const sampleAction = { type: "FETCH_USER", payload: { id: 101 } } as const.
Derive type ActionType = typeof sampleAction.
Create const act: ActionType = sampleAction and print act.type.
1
2
3
4
5
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.