Skip to content

When the initial element of the tuple is a rest element, it is not possible to correctly infer the type of the initial element.ย #56883

@13OnTheCode

Description

@13OnTheCode

๐Ÿ”Ž Search Terms

initial element of the tuple is a rest element

๐Ÿ•— Version & Regression Information

โฏ Playground Link

https://www.typescriptlang.org/play?ts=5.3.2#code/C4TwDgpgBAKgjFAvFA2gOgwZ2AJwJYB2A5igLoA0UBArgLYBGEOl9A9qwDYQCGBpAsACghAEwgBjDtxzRxrAtijScALlhwhQuQuBQAFjxFIlOHCgAMAwVBsB6W1AB6AfiE2o9qAFEAHpHHAECJq2PjEUAA+VHSMOEA

๐Ÿ’ป Code

type T1 = [...string[], number, boolean]

declare const arr: T1

const head = arr[0]
   // Actual: string | number | boolean
   // Expected: string | number

๐Ÿ™ Actual behavior

When the initial element of the tuple is a rest element, it is not possible to correctly infer the type of the initial element.

๐Ÿ™‚ Expected behavior

Infer the correct type.

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions