Skip to content

noUncheckedIndexedAccess failed when destructuring from a tuple with rest elementsΒ #52302

Closed
@whzx5byb

Description

@whzx5byb

Bug Report

πŸ”Ž Search Terms

noUncheckedIndexedAccess destructuring tuple rest elements

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type NonEmptyStringArray = [string, ...Array<string>]

const strings: NonEmptyStringArray = ['one', 'two', 'three']
const [s0, s1, s2, s3] = strings;
//                  ^? const s3: string | undefined
  s3.toUpperCase()
//^? const s3: string

πŸ™‚ Expected behavior

s3.toUpperCase() shows type error.

πŸ™ Actual behavior

s3.toUpperCase() shows no error.
Note that undefined is correctly included inside the assignment statement but then lost.

Related: #40657

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions