typestar

Utility types in TypeScript

The built-in type transformers you reach for daily.

interface User {
  id: number;
  name: string;
  email: string;
  admin: boolean;
}

type Draft = Partial<User>;
type Frozen = Readonly<User>;
type Summary = Pick<User, "id" | "name">;
type Public = Omit<User, "email">;
type Lookup = Record<string, User>;
type Required2 = Required<Draft>;

const patch: Draft = { name: "ada" };

How it works

  1. Partial and Required flip optionality.
  2. Pick and Omit select or remove fields.
  3. Record builds a keyed map type.

Keywords and builtins used here

The run, in numbers

Lines
15
Characters to type
320
Tokens
87
Three-star pace
100 tpm

At the three-star pace of 100 tokens a minute, this run takes about 52 seconds.

Type this snippet

Step 3 of 4 in Reading types, step 7 of 20 in Generics.

← Previous Next →