Skip to content

Generic of union type inferred as {} #5861

Closed
@Arnavion

Description

@Arnavion

(1.8.0-dev.20151201)

interface Foo<T> { prop: T; }

declare function lift<U>(value: U | Foo<U>): Foo<U>;

function unlift<U>(value: U | Foo<U>): U {
    return lift(value).prop; // error TS2322: Type '{}' is not assignable to type 'U'.
}

In 1.6 and 1.7 lift's generic is correctly inferred as U, so prop is of type U as expected. In 1.8 it's inferred as {}

Explicitly specifying the generic with lift<U>(value).prop works.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions