Dev Highlights

Доки по разработке

This project is maintained by teniryte

Расширенные mapped-типы

Принципы

Пример

type Keys = 'one' | 'two' | 'three';

type MappedType = {
  [K in Keys]: number;
};

type Contact = {
  readonly name: string;
  email?: string;
};

type Read<T> = { -readonly [K in keyof T]: T[K] };
type Req<T> = { [K in keyof T]-?: T[K] };

const readContact: Read<Contact> = { name: 'Bob', email: 'bob@mail' };
readContact.name = 'Robert';

Практика