Skip to content

Broken double inference step in variadic tuple types when rest elements come into playΒ #52017

Open
@jfet97

Description

@jfet97

Bug Report

πŸ”Ž Search Terms

variadic tuple type, rest element, infer, unknown[]

It might be related to #51138 and #51157

πŸ•— Version & Regression Information

This is the behavior in every version I tried, nightly included.

⏯ Playground Link

Playground link with relevant code

Minimal repro of the problem

πŸ’» Code

The double inference step is needed to preserve labels of both the first element and the rest.

type HEAD_TAIL<T extends readonly any[]> =
  T extends readonly [any?, ...infer TAIL]
  ? 
    T extends readonly [...infer HEAD, ...TAIL]
    ? {
      HEAD: HEAD;
      TAIL: TAIL;
    }
    : never
  : never;

πŸ™ Actual behavior

The following is inferred as { HEAD: unknown[]; TAIL: [b: 2, ...c: 3[]]; }

type test3 = HEAD_TAIL<[a:1, b:2, ...c: 3[]]>

πŸ™‚ Expected behavior

The expected type is { HEAD: [a:1]; TAIL: [b: 2, ...c: 3[]]; }.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions