Skip to content

Instantly share code, notes, and snippets.

@YouMinTW
Last active August 20, 2021 03:08
Show Gist options
  • Save YouMinTW/0a797366261d1e307acfd1edb9492e6d to your computer and use it in GitHub Desktop.
Save YouMinTW/0a797366261d1e307acfd1edb9492e6d to your computer and use it in GitHub Desktop.
type Simplify<T> = T extends Function
? T
: T extends Record<string, any>
? { [K in keyof T]: Simplify<T[K]> }
: T;
type Author = {
lastName: string;
firstName: string;
};
interface Animal {
live(): void;
}
type Kid = {
bark: (a: string) => number;
qq: {
sing: (b: symbol) => boolean;
shout: Shout;
};
};
type Shout = (a: number, b: boolean, c: string) => Author;
type SomeNestedObject = {
a: Animal;
b: string;
c: { a: Animal; d: Kid; e: { a: Kid; b: Animal } };
};
type SimplifiedObject = Simplify<SomeNestedObject>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment