Skip to content

Type inference not working for this particular use of Generics? #8952

Description

@coreh

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 {}.

Metadata

Metadata

Assignees

No one assigned

    Labels

    By DesignDeprecated - use "Working as Intended" or "Design Limitation" instead

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions