TypeScript Function Overloads Quiz
A 35-question TypeScript quiz covering overload signatures, implementation signatures, narrowing behavior, return types, and best practices for overloaded functions.
Question 1
Function overloads allow developers to declare:
Question 2
Overload signatures appear:
Question 3
Which statement about implementation signatures is correct?
Question 4
What is an overload signature here?
function load(id: number): string;
function load(id: string): string;Question 5
Which line must come last?
function sum(a: number, b: number): number;
function sum(a: string, b: string): string;
function sum(a: any, b: any) { return a + b; }Question 6
Function overloads allow TypeScript to:
Question 7
Overloads can differ by:
Question 8
Which is true for overload parameters?
Question 9
Overloads help model:
Question 10
Which call is allowed?
function format(x: number): number;
function format(x: string): string;
function format(x: any) { return x; }Question 11
Which return type will TypeScript infer?
function get(x: number): number;
function get(x: string): string;
function get(x: any) { return x; }
const result = get('hi');Question 12
Which call will produce an error?
function combine(a: string, b: string): string;
function combine(a: number, b: number): number;
function combine(a: any, b: any) { return a + b; }Question 13
Return-type narrowing is achieved because:
Question 14
Overload signatures must:
Question 15
Which overload will match?
function parse(x: string): number;
function parse(x: number): number;
function parse(x: any) { return Number(x); }
const out = parse(100);Question 16
Why does this error?
function select(x: number): number;
function select(x: string): string;
function select(x: boolean) { return x; }Question 17
Which call is valid?
function ping(): string;
function ping(x: string): string;
function ping(x?: any) { return 'ok'; }Question 18
Which return type is inferred?
function area(r: number): number;
function area(w: number, h: number): number;
function area(...args: any[]) { return 10; }
const a = area(5);Question 19
Which error will occur?
function op(x: number): number;
function op(x: string): string;
function op(x: number | string) { return x; }
const v = op(true);Question 20
Overloads differ from unions because:
Question 21
Overloads should generally be ordered:
Question 22
Which is true about implementation signatures?
Question 23
Overloads can help:
Question 24
Which approach often replaces overloads?
Question 25
Overloads should be avoided when:
Question 26
Which return type is chosen?
function cast(x: number): number;
function cast(x: string): string;
function cast(x: any) { return x; }
const c = cast(10);Question 27
If no overload matches, TypeScript:
Question 28
Overloads are resolved:
Question 29
A mismatch between overloads and implementation:
Question 30
Overloads improve clarity when:
Question 31
Which of the following is NOT required in overload declarations?
Question 32
Overloads cannot:
Question 33
Overload resolution is based primarily on:
Question 34
Overloads may be preferred over unions when:
Question 35
Overall, function overloads help developers:
