extract generic type
📝 TypeScriptExtracts 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.