Skip to content

Instantly share code, notes, and snippets.

@spion
Created August 6, 2019 21:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spion/1513ce1e3c9251c9bcfde16877d8c866 to your computer and use it in GitHub Desktop.
Save spion/1513ce1e3c9251c9bcfde16877d8c866 to your computer and use it in GitHub Desktop.
type ExtractValuesRecusrively<T> = T extends FormState<infer U>
? { [K in keyof U]: ExtractValuesRecusrively<U[K]> }
: T extends FieldState<infer V>
? V
: never;
// vs
type ExtractValuesRecusrively<State> = State extends FormState<infer InnerForm>
? { [FieldKey in keyof InnerForm]: ExtractValuesRecusrively<InnerForm[FieldKey]> }
: State extends FieldState<infer FieldType>
? FieldType
: never;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment