Skip to content

behavior of noUncheckedIndexedAccess is inconsistent.Β #57794

Closed
@13OnTheCode

Description

@13OnTheCode

πŸ”Ž Search Terms

"noUncheckedIndexedAccess" "undefined"

πŸ•— Version & Regression Information

5.4.2

⏯ Playground Link

https://www.typescriptlang.org/play?noUncheckedIndexedAccess=true&exactOptionalPropertyTypes=false&noPropertyAccessFromIndexSignature=false#code/C4TwDgpgBAggTnKBeKBnYcCWA7A5gbQF0AoY0SKAFQEZlYF8AGEgehag4D0B+UgEwgBjADYBDONEEB7bOiji4ALnpxS02cCjBaKBU1bsOUHsSA

πŸ’» Code

type Arr = string[]

type T1 = Arr[0]
//     ^?  type T1 = string

declare const arr: Arr

const t1 = arr[0]
//      ^?  const t1: string | undefined

πŸ™ Actual behavior

behavior of noUncheckedIndexedAccess is inconsistent.

πŸ™‚ Expected behavior

The type obtained from type T1 = Arr[0] should be string | undefined.

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions