Skip to content

Instantly share code, notes, and snippets.

@matthewsimo
Last active May 4, 2022 21:14
Show Gist options
  • Select an option

  • Save matthewsimo/cd9e80a012fcd738a81df51ac6398d67 to your computer and use it in GitHub Desktop.

Select an option

Save matthewsimo/cd9e80a012fcd738a81df51ac6398d67 to your computer and use it in GitHub Desktop.

Revisions

  1. matthewsimo revised this gist May 4, 2022. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions type-utils.ts
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,14 @@
    type WithOptional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
    export type WithOptional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;

    type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
    export type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;

    // expands object types recursively
    type ExpandRecursively<T> = T extends object
    export type ExpandRecursively<T> = T extends object
    ? T extends infer O
    ? { [K in keyof O]: ExpandRecursively<O[K]> }
    : never
    : T;

    type DeepPartial<T> = {
    export type DeepPartial<T> = {
    [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
    };
  2. matthewsimo created this gist May 4, 2022.
    14 changes: 14 additions & 0 deletions type-utils.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    type WithOptional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;

    type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;

    // expands object types recursively
    type ExpandRecursively<T> = T extends object
    ? T extends infer O
    ? { [K in keyof O]: ExpandRecursively<O[K]> }
    : never
    : T;

    type DeepPartial<T> = {
    [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
    };