Hey there. I was experimenting with generics, and noticed that type inference didn't work as I expected for this particular case. I'm not entirely sure if this is an actual blind spot of the type inference mechanism, or if my declaration doesn't mean what I think it means. it's a bit similar to the “Curiously recurring template pattern” described on #5949, but isn't actually the CRTP, since there's no actual recursion involved. Thanks in advance for looking into this issue.
TypeScript Version:
1.8.10
Code
interfaceIFoo{foo: 'foo';// Could be anything}interfaceIWrapped<I>{getObject(): I;}functionunwrap<I,TextendsIWrapped<I>>(x: T): I{returnx.getObject();}letx: IWrapped<IFoo>/* = ... */;lety=unwrap<IFoo,IWrapped<IFoo>>(x);// Type is IFoo (correct)letz=unwrap(x);// Type is {} (incorrect?)Expected behavior:
I expected the compiler to infer the type of z as being IFoo, like when using explicit generic parameters on y.
Actual behavior:
The compiler inferred the type of z as being {}.
Hey there. I was experimenting with generics, and noticed that type inference didn't work as I expected for this particular case. I'm not entirely sure if this is an actual blind spot of the type inference mechanism, or if my declaration doesn't mean what I think it means. it's a bit similar to the “Curiously recurring template pattern” described on #5949, but isn't actually the CRTP, since there's no actual recursion involved. Thanks in advance for looking into this issue.
TypeScript Version:
1.8.10
Code
Expected behavior:
I expected the compiler to infer the type of
zas beingIFoo, like when using explicit generic parameters ony.Actual behavior:
The compiler inferred the type of
zas being{}.