Skip to content
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

Unexpected union type between generic and non-generic function #12970

Closed
gcnew opened this issue Dec 16, 2016 · 2 comments
Closed

Unexpected union type between generic and non-generic function #12970

gcnew opened this issue Dec 16, 2016 · 2 comments
Labels
Needs Investigation This issue needs a team member to investigate its status.

Comments

@gcnew
Copy link
Contributor

gcnew commented Dec 16, 2016

TypeScript Version: nightly (2.2.0)

Code

function id<T>(x: T): T {
    return x;
}

function stringId(x: string): string {
    return x;
}

function numberId(x: number): number {
    return x;
}

// OK: ((x: string) => string) | ((x: number) => number)
const f = true ? numberId : stringId;

// Actual: <T>(x: T) => T
// Expected: (x: string) => string
const g = true ? id : stringId;

Expected behavior:
Union between a function and a generic function should yield the most specific type, not the most general one.

@JsonFreeman
Copy link
Contributor

I agree with the expected behavior. I also wonder if it would be reasonable to not collapse the union and keep both constituents.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label May 24, 2017
@gcnew
Copy link
Contributor Author

gcnew commented Jun 9, 2017

Fixed by #16368

@gcnew gcnew closed this as completed Jul 7, 2017
@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
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

3 participants