Skip to content

Generic of union type inferred as {} #5861

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

Closed
Arnavion opened this issue Dec 1, 2015 · 0 comments
Closed

Generic of union type inferred as {} #5861

Arnavion opened this issue Dec 1, 2015 · 0 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@Arnavion
Copy link
Contributor

Arnavion commented Dec 1, 2015

(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.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Dec 1, 2015
@mhegazy mhegazy added this to the TypeScript 1.8 milestone Dec 1, 2015
@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Dec 3, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants