TypeScript Literal Types and Type Inference Quiz
A 35-question TypeScript quiz about literal types, inference behavior, widening rules, const contexts, and practical modelling using specific literal values.
Question 1
What does a literal type represent?
Question 2
Which of the following is a literal type?
Question 3
What is the type of status?
const status = 'idle';Question 4
Literal types are often used to:
Question 5
What type does TypeScript infer for value?
let value = 'active';Question 6
Which variable declaration preserves literal types by default?
Question 7
What does widening refer to?
Question 8
What is required to perform narrowing on literal unions?
Question 9
What type does kind narrow to inside the if block?
type Mode = 'view' | 'edit';
function run(kind: Mode) {
if (kind === 'edit') {
return 'editing';
}
}Question 10
Literal narrowing enables:
Question 11
Which is a boolean literal type?
Question 12
What is the inferred type of count?
const count = 42;Question 13
Why are string literal unions helpful?
Question 14
What is the type of data?
const data = { state: 'loading' } as const;Question 15
const assertions prevent:
Question 16
What is the type of nums?
const nums = [1, 2, 3] as const;Question 17
When does widening typically occur?
Question 18
What is the inferred type of msg?
let msg = 'hello';Question 19
Widening from literal types helps:
Question 20
What is returned's inferred type?
function getState() {
return 'ready';
}Question 21
Literal types can be combined into:
Question 22
What is the type of lvl?
const lvl: 1 | 2 | 3 = 2;Question 23
Literal inference for arrays without const results in:
Question 24
Literal value sets are commonly used for:
Question 25
Which values can mode accept?
type Mode = 'auto' | 'manual';
let mode: Mode;Question 26
Literal numeric unions can be used to:
Question 27
What is the type of label?
let label = 'high' as const;Question 28
Why can literal widening be surprising?
Question 29
Which describes the effect of a literal annotation?
Question 30
Why must literal sets be updated carefully?
Question 31
Which values does TypeScript widen string literals to?
Question 32
Literal inference for function parameters:
Question 33
Why do object property literals widen unless const-asserted?
Question 34
What does a literal-typed variable prevent?
Question 35
Literal types improve API design by:
