You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Notice how the I.X member is referenced two times - once in the i.X assignment and once in the object literal inside function f(). Now, if I put my caret on the X definition and hit F2, the definition itself and the i.X assignment get renamed, - but the object literal remains as it was. Worse still, because X is an optional property, the compiler doesn't catch the rename at compile time either, and I end up with a good old JavaScript typo situation.
I do realize that it is not always possible for the compiler to know if an object literal is intended to represent an interface or not. For example:
However, I am willing to go an extra mile to help the compiler out here. That's why I put the <I> annotation on the object literal in the first example. The problem, however, is that it's impossible for me to lend the compiler a hand, even when I want to.
This is a very real and painful problem when working with property bags, which is a very common JS pattern.
The text was updated successfully, but these errors were encountered:
RyanCavanaugh
changed the title
Rename function doesn't affect inline object literals
Rename function / find all references doesn't affect inline object literals
Jul 29, 2014
We've definitely wanted to fix this for a while and a minimal implementation shouldn't require any major design (just use contextual typing rules). Let's try to get sign-off on the straightforward cases at least.
Check out this code:
(playground link)
Notice how the
I.X
member is referenced two times - once in thei.X
assignment and once in the object literal inside functionf()
. Now, if I put my caret on theX
definition and hit F2, the definition itself and thei.X
assignment get renamed, - but the object literal remains as it was. Worse still, becauseX
is an optional property, the compiler doesn't catch the rename at compile time either, and I end up with a good old JavaScript typo situation.I do realize that it is not always possible for the compiler to know if an object literal is intended to represent an interface or not. For example:
However, I am willing to go an extra mile to help the compiler out here. That's why I put the
<I>
annotation on the object literal in the first example. The problem, however, is that it's impossible for me to lend the compiler a hand, even when I want to.This is a very real and painful problem when working with property bags, which is a very common JS pattern.
The text was updated successfully, but these errors were encountered: