Explore Library
TypeScriptUtility Types

39 items

1

Partial Update With Omit

Code Quiz
2

Choosing the Right Utility Type

Quiz
3

Utility Types, Enums & Strictness

Slides / Video
4

Utility Types, Enums & Strictness

Flashcard
5

Generics, Unions & Utility Types

Slides / Video
6

Generics, Unions & Utility Types

Flashcard
7

Building Custom Utility Types

Slides / Video
8

Exclude and Extract Distribute Over Unions

Slides / Video
9

Composing Multiple Utility Types

Slides / Video
10

Utility Types Built From Type Operators

Slides / Video
11

String Manipulation Utility Types

Slides / Video
12

Awaited<T> Unwraps Promise Types

Slides / Video
13

ThisParameterType and OmitThisParameter

Slides / Video
14

InstanceType<T> Extracts Instance Types

Slides / Video
15

ConstructorParameters<T> Extracts Constructor Args

Slides / Video
16

Parameters<T> Extracts Argument Types

Slides / Video
17

ReturnType<T> Extracts Return Types

Slides / Video
18

NonNullable<T> Strips Null and Undefined

Slides / Video
19

Extract<T, U> Keeps Matching Union Members

Slides / Video
20

Exclude<T, U> Removes Union Members

Slides / Video
21

Omit<T, K> Excludes Properties

Slides / Video
22

Pick<T, K> Selects a Subset

Slides / Video
23

Record<K, T> Maps Keys to Values

Slides / Video
24

Readonly<T> Locks Every Property

Slides / Video
25

Required<T> Makes Properties Required

Slides / Video
26

Partial<T> Makes Properties Optional

Slides / Video
27

Record with Union Keys

Code Quiz
28

Partial and Required Modifiers

Code Quiz
29

Composing utility types

Quiz
30

Homomorphic modifier preservation

Quiz
31

Implementing utility types

Quiz
32

Deep Partial and Readonly

Quiz
33

Record with literal key sets

Quiz
34

Pick/Omit with index signatures

Quiz
35

Utility types over unions

Quiz
36

ConstructorParameters basics

Quiz
37

ThisParameterType and OmitThisParameter

Quiz
38

ThisType for contextual this

Quiz
39

Omit vs Exclude semantics

Quiz
Code Quiz

Partial Update With Omit

Spot why a partial user update fails to type-check when using Omit.

Codetypescript
interface User {
  id: number;
  name: string;
  email: string;
}

type UserUpdate = Omit<User, "id">;

function updateUser(id: number, changes: UserUpdate) {
  // apply changes to the user with the given id...
}

// Intended: update only the name
updateUser(1, { name: "Alice" }); // Error!

Why does the updateUser call fail to type-check, and how should UserUpdate be fixed?