Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bradzacher opened this issue Feb 24, 2021 · 1 comment · Fixed by #3361
Closed
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule help wanted Extra attention is needed package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@bradzacher
Copy link
Member

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.

@bradzacher bradzacher added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin enhancement: plugin rule option New rule option for an existing eslint-plugin rule labels Feb 24, 2021
@noullet
Copy link

noullet commented Feb 24, 2021

Here is a slightly different situation:

I have the dot-notation rule as "warn" so I thought I could comply with TypeScript and live with the warning until it is properly supported, however lint --fix turns the indexed notation back into dot notation and breaks the TypeScript rule.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule help wanted Extra attention is needed package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
2 participants