TypeScript: noImplicitAny regression in 1.3

Pre 1.3, with --noImplicitAny flag on, having the following:

interface Object {
  [key: string]: any;
}

would enable this type of scenario:

var element = document.querySelector("#something");
element["foo"] = { ... };

However, now this results in an implicit-any error. The winjs/winjs team uses this pattern a lot to add and access members on various objects and this is blocking us from moving to 1.3.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 21 (8 by maintainers)

Most upvoted comments

I feel like we need some kind of solution here, since we already have many thousands of lines of code that rely on it without an easy way to refactor. Also there are plenty of times that it is very ugly to do any casts.

Which do you think is more readable?

obj['foo']

vs

(<any>obj).foo

To me the first is much cleaner, especially when you’re chaining or passing properties values as arguments to other functions.