Closed
Description
TypeScript Version: 3.5.1-3.5.2
Search Terms:
infer type from generic function
Code
type genericProps<T> = {
abcId: string
count: number
flag: boolean
className?: string
as?: T
}
declare function genericFC<T>(props: genericProps<T>): any
type test<T> = typeof genericFC extends <T>(props: infer P) => any ? P : never
Expected behavior:
{
abcId: string
count: number
flag: boolean
className?: string
as?: T
}
Actual behavior:
{
abcId: string
count: number
flag: boolean
className?: string
as?: unknown
}
Playground Link: link
Related Issues:
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
RyanCavanaugh commentedon Jul 2, 2019
This is working as expected. There's no relation between the two
T
s intest
's declaration; i.e. you could equally have writtenI expect what you're trying to do is refer to a specific call instantiation of a generic function, which isn't currently possible.
Pomar81 commentedon Jul 4, 2019
Yes, I wanted to refer to specific call instantiation of a generic function
e.g
genericFC<'div'>
ahejlsberg commentedon Jan 27, 2022
With #47607 it is possible to refer to specific instantiations of generic functions.