Bug Report
π Search Terms
noPropertyAccessFromIndexSignature
π Version & Regression Information
4.2+
- This is the behavior in every version I tried
β― Playground Link
https://www.typescriptlang.org/play?noPropertyAccessFromIndexSignature=true#code/FAGwpgLgBBYM4QFxQN4G0CWA7AJmAHoggE7YDmAukRKVmQL5QC8qwU7UA9J1AO5h8AhlmgQAFhjgwA9lABGAgMaCArmTHQ5ATyhZpABWLSADmGIQtAQUWL4cAGJGAtgElcBAMoYyWQRBXEYAA08irQGOFwWADkEAB0bByCcorI0RLRQYnseABmaWJgICDSmcD0ANzAwIrSWHDS4HElZAAUsAhxyYoAlFW19Y1gzdJtHfF5fTV1DU0t7fAQaNHd0RRTA7PD8+PLeWt9QA
π» 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.
Bug Report
π Search Terms
noPropertyAccessFromIndexSignature
π Version & Regression Information
4.2+
β― Playground Link
https://www.typescriptlang.org/play?noPropertyAccessFromIndexSignature=true#code/FAGwpgLgBBYM4QFxQN4G0CWA7AJmAHoggE7YDmAukRKVmQL5QC8qwU7UA9J1AO5h8AhlmgQAFhjgwA9lABGAgMaCArmTHQ5ATyhZpABWLSADmGIQtAQUWL4cAGJGAtgElcBAMoYyWQRBXEYAA08irQGOFwWADkEAB0bByCcorI0RLRQYnseABmaWJgICDSmcD0ANzAwIrSWHDS4HElZAAUsAhxyYoAlFW19Y1gzdJtHfF5fTV1DU0t7fAQaNHd0RRTA7PD8+PLeWt9QA
π» Code
π 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.