wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

TypeScript Quiz

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Why does TypeScript follow structural typing instead of nominal typing?

a)

To improve execution speed of programs

b)

To match types based on their structure

c)

To strictly enforce class inheritance rules

d)

To completely avoid type inference

2.

What is a key difference between interface and type in TypeScript?

a)

Interfaces allow union types by default

b)

Types allow declaration merging

c)

Interfaces support declaration merging

d)

Types are always more flexible

3.

What additional safety does the unknown type provide over any?

a)

It allows unrestricted variable operations

b)

It disables all compile-time checks

c)

It requires explicit type checking

d)

It restricts values to primitive types

4.

What is the main purpose of the never type in TypeScript?

a)

To represent optional function returns

b)

To represent impossible code paths

c)

To store null or undefined values

d)

To replace void return types

5.

Why are generics considered powerful in TypeScript?

a)

They improve runtime execution speed

b)

They enable reusable type-safe logic

c)

They remove the need for interfaces

d)

They enforce strict runtime checking

6.

What does the following generic constraint guarantee?
function logLength<T extends { length: number }>(arg: T): T

a)

The argument must be an array

b)

The argument must be a string

c)

The argument has a length property

d)

The argument supports iteration

7.

What is the primary use of union types in TypeScript?

a)

To reduce repeated code blocks

b)

To perform runtime type checking

c)

To allow multiple possible types

d)

To optimize application performance

8.

Why are type guards essential in TypeScript programs?

a)

They prevent memory-related issues

b)

They narrow types within code blocks

c)

They eliminate the need for type casting

d)

They increase application performance

9.

What benefit does TypeScript’s type inference mainly provide?

a)

It removes the need for JavaScript

b)

It ensures safety with less syntax

c)

It enforces types everywhere strictly

d)

It avoids all runtime errors

10.

Why are TypeScript types removed after compilation?

a)

They are required only during development

b)

JavaScript engines cannot read types

c)

They reduce runtime execution speed

d)

They are converted into metadata