Skip to content

Incorrect intersection of inferred generic string types #19657

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
TPReal opened this issue Nov 1, 2017 · 0 comments
Closed

Incorrect intersection of inferred generic string types #19657

TPReal opened this issue Nov 1, 2017 · 0 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@TPReal
Copy link

TPReal commented Nov 1, 2017

TypeScript Version: 2.6.1

Code

declare function func<A extends string,B extends A>(a:A,b:B[]):
    (ab:A&B)=>void;
const q=func("x" as "x"|"y",["x"]);
q("x");

Expected behavior:
Should compile: A is "x"|"y", B is "x", so A&B is "x".

Actual behavior:
Does not compile: q is of type (ab:never)=>void.

Hovering over the func call in TS Playground shows this:
function func<"x" | "y", "x">(a: "x" | "y", b: "x"[]): (ab: never) => void
which suggests both A and B were correctly inferred, but still A&B is wrong.

Another data point: removing extends string requirement on A makes it work (although then B is "x"|"y"). Also if func takes b:B (not array) as second argument, then it works.

@mhegazy mhegazy added the Bug A bug in TypeScript label Nov 1, 2017
@ahejlsberg ahejlsberg added this to the TypeScript 2.7 milestone Nov 2, 2017
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Jan 11, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 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

3 participants