Open
Description
Bug Report
π Search Terms
noPropertyAccessFromIndexSignature
π Version & Regression Information
4.2+
- This is the behavior in every version I tried
β― Playground Link
π» Code
let test: {[index:string]:string} = {
// we want this to be caught by noPropertyAccessFromIndexSignature, but it isn't.
abc: 'hi',
def: 'hello',
};
console.log(test.abc); // reported
console.log(test.def); // reported
console.log(test['abc']); // OK
console.log(test['def']); // OK
π Actual behavior
Unquoted string keys are allowed when assigned to types with index signatures.
π Expected behavior
Some mechanism for restricting the definitions of object literals so that only named properties are allowed to be provided without quotes ( {['somekey']: value}
or {'somekey':value}
. This would both prevent logic errors and improve compatibility with Closure Compiler's ADVANCED optimizations.