Skip to main content
TypeScript Code Completion Hard +35 XP

Mapped Type

Complete the mapped type.

TypeScriptFill in the blank
type Readonly<T> = {
    ___[P in keyof T]: T[P];
};

Type the missing code

Show answer and explanation

Answer: readonly

Mapped types iterate over keys with 'in keyof'. Adding 'readonly' makes all properties read-only.

Hint: What modifier makes properties immutable?

What this challenge tests

Code Completion in TypeScript: mapped-types, utility-types.

Related challenges