NEW
Font size
WorksheetsTypeScript Quiz
Total questions: 10
Worksheet time: 5mins
Why does TypeScript follow structural typing instead of nominal typing?
To improve execution speed of programs
To match types based on their structure
To strictly enforce class inheritance rules
To completely avoid type inference
What is a key difference between interface and type in TypeScript?
Interfaces allow union types by default
Types allow declaration merging
Interfaces support declaration merging
Types are always more flexible
What additional safety does the unknown type provide over any?
It allows unrestricted variable operations
It disables all compile-time checks
It requires explicit type checking
It restricts values to primitive types
What is the main purpose of the never type in TypeScript?
To represent optional function returns
To represent impossible code paths
To store null or undefined values
To replace void return types
Why are generics considered powerful in TypeScript?
They improve runtime execution speed
They enable reusable type-safe logic
They remove the need for interfaces
They enforce strict runtime checking
What does the following generic constraint guarantee?
function logLength<T extends { length: number }>(arg: T): T
The argument must be an array
The argument must be a string
The argument has a length property
The argument supports iteration
What is the primary use of union types in TypeScript?
To reduce repeated code blocks
To perform runtime type checking
To allow multiple possible types
To optimize application performance
Why are type guards essential in TypeScript programs?
They prevent memory-related issues
They narrow types within code blocks
They eliminate the need for type casting
They increase application performance
What benefit does TypeScript’s type inference mainly provide?
It removes the need for JavaScript
It ensures safety with less syntax
It enforces types everywhere strictly
It avoids all runtime errors
Why are TypeScript types removed after compilation?
They are required only during development
JavaScript engines cannot read types
They reduce runtime execution speed
They are converted into metadata
