TypeScript Version: 3.1.0-dev.20180813
Search Terms:
Tuple rest generic union
Code
declare function hmm<A extends [] | [number, string]>(...args: A): void;
hmm(); // okay, A = []
hmm(1, "s"); // okay, A = [1, "s"]
hmm("what"); // no error? A = [] | [number, string] ?
Expected behavior:
Error on hmm("what"). A should be inferred as [string], which does not extend [] | [number, string].
Actual behavior:
No error on hmm("what"). Apparently A is inferred as the constraint type [] | [number, string] despite that not matching the actual argument type.
Playground Link:
Link
Related Issues:
#24897: introduction of tuples into rest/spread expressions
#26110: similar issue with bad or weird inference behavior on rest arguments