TypeScript Mapped Type

Description

A mapped type can create new object types based on arbitrary keys or new object types based on other object types.

Syntax

type Options = {
[K in “noImplicitAny” | “strictNullChecks” | “strictFunctionTypes”]?: boolean
};
// same as
// type Options = {
// noImplicitAny?: boolean,
// strictNullChecks?: boolean,
// strictFunctionTypes?: boolean
// };

/// ‘Partial’ is the same as ‘T’, but with each property marked optional.
type Partial = {
[K in keyof T]?: T[K]
};

Clauses

  • [TypeScript as Clause](TypeScript as Clause)