← Back to Gists

extract generic type

📝 TypeScript
aellis
aellis · Level 6 ·

Extracts the underlying generic type from a TypeScript type, such as pulling string from Promise<string>.

TypeScript
type ExtractGeneric<T> = T extends Promise<infer U> ? U : T; type Example = ExtractGeneric<Promise<string>>; // string
type Example2 = ExtractGeneric<number>; // number

Comments

No comments yet. Start the discussion.