8000 Generic parameters constrained to unions of tuples are not inferred correctly in rest parameter positions · Issue #26491 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content
Generic parameters constrained to unions of tuples are not inferred correctly in rest parameter positions #26491
Closed
@jcalz

Description

@jcalz

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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0