Skip to content

noUncheckedIndexedAccess w/ destructuringΒ #56154

Closed as not planned
Closed as not planned
@arcanis

Description

@arcanis

πŸ” Search Terms

noUncheckedIndexedAccess, destructuring

βœ… Viability Checklist

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals

⭐ Suggestion

The ! qualifier should be allowed in destructuring patterns:

const [x!, y!, {z!}!] = someArrayValue;

πŸ“ƒ Motivating Example

This feature makes migrating a large codebase to noUncheckedIndexedAccess easier, as we no longer need to migrate all existing destructuring patterns in one go.

πŸ’» Use Cases

We're working to enable noUncheckedIndexedAccess on a very large codebase (10k+ files). I wrote a codemod adding the ! qualifier to existing unchecked accesses, but while it's easy to do this on foo[expr] and foo.prop nodes, I didn't find a good solution for destructured accesses:

const [x, y, {z}] = someArrayValue;

The following doesn't parse, where it seems it should:

const [x!, y!, {z!}!] = someArrayValue;

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions