Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[dot-notation] add support for TS4.2's noPropertyAccessFromIndexSignature optionΒ #3104

Closed
@bradzacher

Description

@bradzacher

Repro

{
  "rules": {
    "@typescript-eslint/dot-notation": ["error"]
  }
}
interface GameSettings {
  // Known up-front properties
  speed: "fast" | "medium" | "slow";
  quality: "high" | "low";

  // Assume anything unknown to the interface
  // is a string.
  [key: string]: string;
}

declare const settings: GameSettings;

// good
settings.speed;
settings.quality;

// required to satisfy noPropertyAccessFromIndexSignature, but causes a dot-notation error
settings['username'];

We should add detection for the noPropertyAccessFromIndexSignature, and add logic so that it allows indexed access in the same cases.

This will allow you to use both this rule and the compiler option simultaneously.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions