Typescript: `for ... in obj` where `obj: object` gives TS2407

Created on 20 Feb 2017  路  8Comments  路  Source: microsoft/TypeScript



TypeScript Version: 2.2.0

$ node_modules/.bin/tsc --version
Version 2.2.0

Code

let obj: object = {}

for (const attr in obj) {
  const val = obj[attr]
}

Expected behavior:

Compiles without errors.

Actual behavior:

some.ts(3,20): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter.

This is a new feature, so I'm not sure if I'm using this properly, but the error message says that an object type is allowed, so I expect this behavior to be a bug.

Bug Fixed

Most helpful comment

Thanks for reporting! I'm looking on it!

All 8 comments

Try spelling object in uppercase: Object

No, object should be acceptable here. Looks like a bug.

Thanks for reporting! I'm looking on it!

+1

thanks @HerringtonDarkholme!

Is this in the next 2.3.0 release?

I pulled down the 2.3.0 release off nom and I'm still seeing this error.

c:\test\sandbox7>tsc --v
Version 2.3.0

c:\test\sandbox7>type a.ts
let obj: object = {}

for (const attr in obj) {
  const val = obj[attr]
}
c:\test\sandbox7>tsc a.ts

c:\test\sandbox7>echo %ERRORLEVEL%
0
Was this page helpful?
0 / 5 - 0 ratings

Related issues

MartynasZilinskas picture MartynasZilinskas  路  3Comments

jbondc picture jbondc  路  3Comments

kyasbal-1994 picture kyasbal-1994  路  3Comments

wmaurer picture wmaurer  路  3Comments

uber5001 picture uber5001  路  3Comments