Closed
Description
TypeScript Version: 3.1.0-dev.20180803
Search Terms:
Code
// @filename: test.js
// @strict: true
/*1*/
let empty = {};
empty.foo;
/*2*/
let key = Math.random();
let computed = {[key]: 1};
computed[key];
Expected behavior:
empty
has no index signature.
computed
has an index signature {[x: number]: number}
.
There's no implicitAny error on the element access computed[key]
.
Actual behavior:
None of the object literals has an index signature. This causes the element access computed[key]
to have an implicitAny error.
Note that this is not an error in a TS file.
Related Issues:
This is caused by @weswigham's PR #25996. I agree with not adding an implicit string index signature to every JS object literal. But not adding one where it makes sense just loses type information.