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

Generic parameters constrained to unions of tuples are not inferred correctly in rest parameter positions #26491

Closed
jcalz opened this issue Aug 16, 2018 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@jcalz
Copy link
Contributor

jcalz commented Aug 16, 2018

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

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Aug 16, 2018
@RyanCavanaugh
Copy link
Member

@ahejlsberg I'm probably missing something here but this seems bad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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