Skip to content

Incorrect intersection of inferred generic string types #19657

@TPReal

Description

@TPReal

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.

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