TypeScript Version: 3.2.0-dev.201xxxxx
Search Terms:
object.keys
Code
type Keys = 'one' | 'two'
const obj:{[key in Keys]: string} = {
one: 'value for one',
two: 'value for two',
}
Object.keys(obj).forEach(key =>
console.log(obj[key])
)
Expected behavior:
No error.
Actual behavior:
$ tsc --noImplicitAny test.ts
test.ts:9:15 - error TS7017: Element implicitly has an 'any' type because type '{ one: string; two: string; }' has no index signature.
9 console.log(obj[key])
~~~~~~~~
Playground Link:
Related Issues: