Skip to content

Instantly share code, notes, and snippets.

@THEtheChad
Last active August 23, 2023 03:09
Show Gist options
  • Save THEtheChad/c5ddf52f97a46d84ae75e9deb9878d33 to your computer and use it in GitHub Desktop.
Save THEtheChad/c5ddf52f97a46d84ae75e9deb9878d33 to your computer and use it in GitHub Desktop.
type Narrow<T> =
| (T extends Function ? T : never)
| (T extends string | number | bigint | boolean ? T : never)
| (T extends [] ? [] : never)
| {
[K in keyof T]: Narrow<T[K]>;
};
function narrow<T extends object>(input: Narrow<T>){
return input
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment