Skip to content

Treatment of recursive tuples that utilize type spread. #40229

@harrysolovay

Description

@harrysolovay

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs InvestigationThis issue needs a team member to investigate its status.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions