Skip to content
Justice Tech School

Utility Types

Built-in helpers transform types: Partial makes everything optional, Required the opposite, Pick keeps chosen keys, Omit removes keys, Readonly freezes and Record builds an object type from keys.

Example
interface User { id: number; name: string; email: string }
type Draft = Partial<User>;
type Preview = Pick<User, "id" | "name">;
type NoEmail = Omit<User, "email">;
const d: Draft = { name: "Ada" };
const p: Preview = { id: 1, name: "Ada" };
const scores: Record<string, number> = { ada: 90, tunde: 80 };
console.log(d, p, scores);

Result

{
  name: "Ada",
} {
  id: 1,
  name: "Ada",
} {
  ada: 90,
  tunde: 80,
}

Exercise

Make all properties optional.

type D = <User>;

Quiz Test

Which helper removes keys?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.