microsoft / microsoft/TypeScript

Treatment of recursive tuples that utilize type spread.

Open
#40,229 3 comments 13 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs Investigation
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 4.0.2

Search Terms: spread tuple in recursive tuple type

Code

I'm trying to model a type that could evaluate to any of the following:

["list", "of", "Post"];
["list", "of", "list", "of", "Post"];
["list", "of", "list", "of", "list", "of", "Post"];
// ... could go on

The following approach produces a circularity error, even though tuple types are circularity-capable since 3.7 :/

type Nested = ["list", "of", ...(["Post"] | Nested)];

Expected behavior:

To be able to type-check the following (for example):

const nested: Nested = ["list", "of", "list", "of", "Post"];

Actual behavior:

Circularity error.

Any help would be greatly appreciated! Thank you!

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.

Research direction

No source file or test is named. Start by reproducing the circularity error with the provided TypeScript 4.0.2 recursive tuple example, then trace the type-checker handling for recursive tuple types and type spreads. Done means the sample declaration and nested value type-check without the circularity error, with coverage added in the appropriate compiler test area.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.