Anyone know how to achieve this (other than developing ESLint plugin)?
interface MyInterface {
Prop1: unknown;
[key: string]: unknown;
}
const dotNotationTest = {} as MyInterface;
dotNotationTest.Prop1 = "ABC";
dotNotationTest.key = "ABC"; // OK, prevented by tsConfig "noPropertyAccessFromIndexSignature": true
dotNotationTest["AnotherKey"] = "ABC";
const objectliteral: MyInterface = {
Prop1: "ABC",
key: "ABC", // Not OK. How to get warning similar to dotNotationTest.key
["AnotherKey"]: "ABC"
};
I could not find any relevant tsconfig option or rule for ESLint. Rule based on abstract syntax tree (no-restricted-syntax
) can't be applied here as key is not different from Prop1 (from parser perspective)
Playground