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

Closed
@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