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.
TypeScript Version: 2.6.1
Code
Expected behavior:
Should compile:
Ais"x"|"y",Bis"x", soA&Bis"x".Actual behavior:
Does not compile:
qis 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) => voidwhich suggests both
AandBwere correctly inferred, but stillA&Bis wrong.Another data point: removing
extends stringrequirement onAmakes it work (although thenBis"x"|"y"). Also if func takesb:B(not array) as second argument, then it works.