Skip to content

Instantly share code, notes, and snippets.

@cenkce
Last active February 12, 2020 17:30
Show Gist options
  • Save cenkce/aa4f89c17bf2fcc12cc44ebe88352000 to your computer and use it in GitHub Desktop.
Save cenkce/aa4f89c17bf2fcc12cc44ebe88352000 to your computer and use it in GitHub Desktop.
// Extracts only non nested values
type ExtractValue<T extends {[key:string]: any}> = T extends {[key:string]: any} ? T[keyof T] : T;
// Recusively extracts values
type ExtractValues<T extends {[key:string]: any}> = T extends {[key:string]: any} ? ExtractValue<T[keyof T]> : never;
type ValuesOfComplexType = ExtractValues<ComplexType>;
// or
type ValuesOfComplexType = ExtractValues<typeof ComplexConstants>;
// assings the values
// "any value 1" | "any value 2" | "any value 3" | "any value 4" ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment