Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Description
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I havesearched for related issues and found none that matched my issue.
- I haveread the FAQ and my problem is not listed.
Playground Link
Repro Code
typeExtraKey= `extra${string}`;typeStructureWithExtras={foo:string;bar:boolean;[extraKey:ExtraKey]:number;}conststructureWithExtras:StructureWithExtras={foo:"hello",bar:false,extraAbc:42,extraDef:42,}console.log(structureWithExtras.foo)console.log(structureWithExtras.bar)console.log(structureWithExtras.extraAbc)console.log(structureWithExtras.extraDef)console.log(structureWithExtras["extraAbc"])console.log(structureWithExtras["extraDef"])
ESLint Config
module.exports={parser:"@typescript-eslint/parser",rules:{"@typescript-eslint/dot-notation":"error",},};
tsconfig
{"compilerOptions": {"noPropertyAccessFromIndexSignature":true }}Expected Result
I expectedstructureWithExtras["extraAbc"] to not produce["extraAbc"] is better written in dot notation
Actual Result
structureWithExtras.extraAbcis not liked bytscstructureWithExtras["extraAbc"]is not liked by@typescript-eslint/dot-notation
Additional Info
Just usingRecord<ExtraKey, number> produces the same deadlock (Playground):
typeExtraKey= `extra${string}`;typeStructureWithJustExtras=Record<ExtraKey,number>;conststructureWithJustExtras:StructureWithJustExtras={extraAbc:42,extraDef:42,};console.log(structureWithJustExtras.extraAbc);console.log(structureWithJustExtras.extraDef);console.log(structureWithJustExtras["extraAbc"]);console.log(structureWithJustExtras["extraDef"]);
ReplacingRecord<ExtraKey, number> withRecord<string, number> helps (Playground):
typeStructureWithStringKeys=Record<string,number>;conststructureWithStringKeys:StructureWithStringKeys={extraAbc:42,extraDef:42,};console.log(structureWithStringKeys.extraAbc);console.log(structureWithStringKeys.extraDef);console.log(structureWithStringKeys["extraAbc"]);console.log(structureWithStringKeys["extraDef"]);
However, usingRecord<string, number> would not be possible in the original example wherenumber value is used alongsidestring andboolean.