Skip to main content

Cheat Sheet Tables

TypeScript Power Tools Cheat Sheet

UtilityPurposeExample
Partial<T>Make all props optionalPartial<User>
Required<T>Make all props requiredRequired<User>
Readonly<T>Make all props readonlyReadonly<User>
Pick<T, K>Pick some keysPick<User, id' | 'name'>
Omit<T, K>Remove some keysOmit<User, 'password'>
NonNullable<T>Remove null & undefinedNonNullable<string | null>
Record<K, V>Create a key-value mapRecord<string, number>
Exclude<T, U>Remove types assignable to UExclude<'a' | 'b', 'a'> // 'b'
Extract<T, U>Keep only types assignable to UExtract<'a' | 'b', 'a'> // 'a'
ReturnType<F>Get return type of a functionReturnType<typeof getUser>
Parameters<F>Get parameter types of a functionParameters<typeof getUser>
Awaited<T>Get resolved type of a PromiseAwaited<Promise<User>> // User
Indexed AccessGrab part of a typeUserQuery['profile']

Common Real-World TypeScript Combos

ComboPurposeExample
Pick<ParentType['nested'], K>Extract specific keys from a nested typePick<AccountQuery['user'], 'id' | 'name'>
Omit<ParentType['nested'], K>Remove unwanted keys from a nested typeOmit<AccountQuery['user'], 'password'>
Partial<ParentType['nested']>Make a nested type partially optionalPartial<AccountQuery['user']>
Required<Pick<T, K>>Ensure a subset of props are requiredRequired<Pick<User, 'email'>>
NonNullable<ParentType['nested']>Remove null and undefined from a nested typeNonNullable<AccountQuery['user']>
ReturnType<typeof fn> + Pick<>Grab only the needed parts of a function's returnPick<ReturnType<typeof getUser>, 'id'>
Partial<Pick<T, K>>Optional subset for mock/test dataPartial<Pick<User, 'id' | 'name'>>
Omit<ReturnType<typeof fn>, K>Drop noisy keys from function return typesOmit<ReturnType<typeof getUser>, 'metadata'>
Indexed Access + Partial<>Make part of a deeply nested object optionalPartial<AccountQuery['user']['stats']>
Pick<Extract<T, U>, K>Combine filtering + selectionPick<Extract<UserRole, 'admin' | 'moderator'>, 'permissions'>

Utility Types

Partial

NonNullable