Skip to content

Instantly share code, notes, and snippets.

@YouMinTW
Created August 19, 2021 02:02
Show Gist options
  • Save YouMinTW/cbc156357e3b6c0ffb10cfaaffa904e5 to your computer and use it in GitHub Desktop.
Save YouMinTW/cbc156357e3b6c0ffb10cfaaffa904e5 to your computer and use it in GitHub Desktop.
type Example<T> = T extends Record<string, any> ? keyof T : T;
// type T1 = number | keyof string[]
type T1 = Example<string[]>;
// type T2 = "a" | "b"
type T2 = Example<{ a: number; b: string }>;
// type T3 = boolean
type T3 = Example<boolean>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment