Skip to content

A rest element type must be an array type. error regression on 4.5.0-dev.20211003 when using spread expression with a generic that returns a tuple (does not hapen on v4.4.3)Β #46183

Description

@ruohola

Bug Report

πŸ”Ž Search Terms

  • A rest element type must be an array type.
  • Error on spread expression with a generic that returns a tuple

πŸ•— Version & Regression Information

  • This changed between versions v4.4.3 and 4.5.0-dev.20211003

⏯ Playground Link

4.5.0-dev.20211003 Playground link (error happens)
v4.4.3 Playground link (no errors)

πŸ’» Code

type NTuple<N extends number, Tup extends unknown[] = []> =
  Tup['length'] extends N ? Tup : NTuple<N, [...Tup, unknown]>;

type Add<A extends number, B extends number> =
  [...NTuple<A>, ...NTuple<B>]['length'];
/* ~~~~~~~~~~~~
   A rest element type must be an array type. (2574)
*/

let five: Add<2, 3>;

πŸ™ Actual behavior

Getting a A rest element type must be an array type. error for ...NTuple<A>.

πŸ™‚ Expected behavior

No errors should happen, and no error happens on TypeScript v4.4.3.

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueRecent RegressionThis is a new regression just found in the last major/minor version of TypeScript.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions