Lesson 30 of 55
15 mins readPython Default Type Arguments and Generic Inference
In Plain English
Default type arguments allow generic interfaces and functions to be invoked without explicit type parameters while still allowing callers to override them.
Core Rules to Remember

Defaults (<T = string>): Provides sensible fallback types when type parameters are omitted.

Call-Site Inference: TypeScript automatically infers generic arguments from values passed to parameters.
Live Interactive Example
Hit Run Code to see it liveSupplying Default Type Arguments
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Output Console
Click "Run Code" to view the rendered output.
How it works: plainResult uses defaults, while typedResult explicitly overrides TData.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Build a Container with Default Type
Define interface Container<T = string> { item: T }.
Create c1: Container = { item: "Zen" } and c2: Container<number> = { item: 99 }.
Print `c1: ${c1.item}, c2: ${c2.item}`.
1
2
3
4
5
6
7
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.