microsoft / microsoft/TypeScript

Variadic tuple constraint incoherent ?

Open
#39,713 1 comment 0 reactions 1 assignee View on GitHub

@ahejlsberg is already working on this.

Since Jul 23, 2020.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 4.0.0-dev.20200722

Search Terms:
Variadic tuple
Variadic tuple constraint

Code

type A<GArgs extends [number, string, ...any[]]> = true;
type B<GArgs extends [string, ...any[]]> = A<[number, ...GArgs]>; // ERROR
type C = A<[number, ...[string, ...any[]]]>; // OK

Actual / Expected behavior:

On the type B we get an error:

TS2344: Type '[number, ...GArgs]' does not satisfy the constraint '[number, string, ...any[]]'.   Element at index 1 is variadic in one type but not in the other

Sounds incorrect because on B, GArgs is properly shaped to be just like in C

Playground Link

Related Issues:

The variadic issues are a big jungle, and I was not able to find any related issue (but probably some exists?)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.