-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't infer generic argument, recursive / nested usage #33858
Comments
I've tried a ton of variations, here's another, note const Test = gloss2<{ a: number }>()
const Test2 = gloss2<{ b: number }>(Test)
interface Thing<X> {
}
function gloss2<A>(a?: any): Thing<A>
function gloss2<B = {}, A = {}>(a?: Thing<A>): Thing<A & B> {
return 0 as any
} Another, using infer: const Test = gloss2<{ a: number }>()
const Test2 = gloss2<{ b: number }>(Test)
interface Thing<X extends object = {}> {}
type InferProps<A> = A extends Thing<infer X> ? X : {}
function gloss2<
B extends object = {},
A extends Thing = Thing
>(a?: A): Thing<InferProps<A> & B> {
return 0 as any
} |
The issue here is that we don't support partial type inference, i.e. explicitly specifying some type arguments and inferring the rest from the argument list. Once you explicitly specify some type arguments, any remaining omitted ones are always given their declared default value, regardless of the argument list. We have a proposal to support partial type inference in #26242, so I'll mark this as duplicate. |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
TypeScript Version: 3.6.3 and 3.7-beta
Code
https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=22&pc=1#code/LAKAxg9gdgzgLgAgCoFN4ILwIOYBsIwwBMAPAN4ICGAXAlAK4C2ARigE4IC+AfABT1QAJigBmASygpBASlCgA9PIRsUjCADcUCOAE8ADiggjkaRJSEIxiZisoBrGAqVWEMABYR6uQZagj22m5aFDR0TKwcnAA0CMz0iADu0HCgkLCIqPBEmDj4hKQUzLQMLAHR2vqGxplwfDXSAHRwQYwovAAemNwIZKAICO0NlH0DDcygnLIgoLoGyG4S2CQAGt1YvSD97bTLI82qKLS8YEUIHTvSXVRQOpcY3UgLUEurE3IgIgJgcGLQuQTEEgAQRiACEcuYdHwRpQAPy0UFREbMeEIIGgaS0R6LYEIABkZ3BKHacBQQhg8xxEn8HAAwt1YQhaQhaGRJt0Nv0VHB6GwoAgAAxUCmQt4gIA
Expected behavior:
Test2
should be able to infer the generics fromTest
, but if you remove thetypeof Test
argument from the playground above you'll see it can't infer it.Related Issues:
I believe this may be related to: #30134
But I'm not sure. In this case it doesn't seem very complex at all, yet I've tried this same snippet of code now every possible permutation I could imagine and none of them seem able to work. Really, I've been scratching my head on this one, it seems simple.
The text was updated successfully, but these errors were encountered: