Skip to content

Utility Types

Eric Taylor edited this page Jul 15, 2019 · 1 revision
TypeScript Notes
Keys keyof T
Values T[keyof T]
Readonly Readonly<T>
Exact T
Class typeof T
Subtype B extends A
Shape Partial<T> Makes all properties optional.
Required Required<T> Makes all properties required.
Return type ReturnType<T>, ReturnType<typeof someFunction>
Property type T[k]
Element type T[k]
Rest Exclude<A, B>
Difference / Omit Pick<A, Exclude<keyof A, B>> Omit is a type as of version 3.5
Pick Pick<T, T[k]> Useful when typing defaultProps (don't use Partial to type defaultProps). Example: const defaultProps: Pick<ComponentProps, 'key1' | 'key2'> = {...};

Clone this wiki locally