Skip to content

Instantly share code, notes, and snippets.

@matthewsimo
Last active May 4, 2022 21:14
Show Gist options
  • Save matthewsimo/cd9e80a012fcd738a81df51ac6398d67 to your computer and use it in GitHub Desktop.
Save matthewsimo/cd9e80a012fcd738a81df51ac6398d67 to your computer and use it in GitHub Desktop.
Typescript Type Utils
export type WithOptional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
export type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
// expands object types recursively
export type ExpandRecursively<T> = T extends object
? T extends infer O
? { [K in keyof O]: ExpandRecursively<O[K]> }
: never
: T;
export type DeepPartial<T> = {
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment