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
I believe the request is to understand that Event<T> does not match the non-generic global Event type from lib.dom.d.ts and may be defined somewhere else.
Not sure if this makes sense since though since accidentally trying to use a non-generic type as a generic could also be a programmer error which should not result in an import quick fix
I often encounter this issue with classes Position and Range. They have nothing to do with generics... It appears the lib.d.ts contains definitions for those too and the quick fix never realizes the global definition is not what I want (in order to suggest an import quick fix)
Perhaps the import quick fix should always be presented on a symbol that is available from a global .d.ts, but which can be imported from somewhere else in the project?
The auto-imports for these symbols are already in the completion list, so that's the best way to import these if that's what you intend to do.
Apart from the edge cases where the reference to the type is provably wrong (which is, AFAICT, only when their generic arities don't match, which I imagine is very rare for any two types of the same name), then there's not really anything we can do in terms of a "quick fix" -- once the reference to the type is legal, any further errors or unexpected behavior aren't distinguishable from normal typos or misunderstanding. More problematically, even offering something like "Overwrite the reference to Position with an auto-import at the place it was declared" might alter a file other than the one you're editing and cause downstream problems elsewhere. At the end of the day the editor can't be sitting around second-guessing code that is facially valid without creating even worse user friction, performance problems, or both.
The problem is that there's no way to know until after you've used a type that it's wrong. In the case of Event, you can imagine a quick fix to suggest another type where the heuristic is "this one takes type arguments, this one doesn't". That's a potentially reasonable one, and I was personally not against it, but a few people in the editor sync felt like that could potentially be noisy if we suggested the wrong type.
In the case of Alexandru Dima (@alexdima)'s example, there's no way until any arbitrary operation to know that the type is "wrong"; even if you can figure that out, figuring out which type is "right" could be expensive to do it accurately.
Now you mentioned that there's no way to auto-import Event because the global overrides it. That shouldn't be the case, but when we experimented with it in the editor sync, we noticed that a lot of the time, auto-imports are significantly deprioritized to the point where they aren't noticed.
Trying it out on your codebase, I'm definitely seeing Event come up (though unfortunately it looks like there are duplicates?)
Daniel Rosenwasser (@DanielRosenwasser) ah yeah good point about the import when you type the name, that helps. I think I often just copy this over from an interface and then miss the suggested auto imports.
Activity
mjbvz commentedon Nov 29, 2018
I believe the request is to understand that
Event<T>does not match the non-generic globalEventtype fromlib.dom.d.tsand may be defined somewhere else.Not sure if this makes sense since though since accidentally trying to use a non-generic type as a generic could also be a programmer error which should not result in an import quick fix
alexdima commentedon Oct 31, 2019
I often encounter this issue with classes
PositionandRange. They have nothing to do with generics... It appears thelib.d.tscontains definitions for those too and the quick fix never realizes the global definition is not what I want (in order to suggest an import quick fix)Perhaps the import quick fix should always be presented on a symbol that is available from a global .d.ts, but which can be imported from somewhere else in the project?
RyanCavanaugh commentedon Aug 19, 2020
The auto-imports for these symbols are already in the completion list, so that's the best way to import these if that's what you intend to do.
Apart from the edge cases where the reference to the type is provably wrong (which is, AFAICT, only when their generic arities don't match, which I imagine is very rare for any two types of the same name), then there's not really anything we can do in terms of a "quick fix" -- once the reference to the type is legal, any further errors or unexpected behavior aren't distinguishable from normal typos or misunderstanding. More problematically, even offering something like "Overwrite the reference to
Positionwith an auto-import at the place it was declared" might alter a file other than the one you're editing and cause downstream problems elsewhere. At the end of the day the editor can't be sitting around second-guessing code that is facially valid without creating even worse user friction, performance problems, or both.bpasero commentedon Aug 20, 2020
Sorry I do not follow. In VSCode I cannot import our
Eventtype because the one inlib.dom.d.tsis assumed:Please let me know how I can clarify this better.
bpasero commentedon Aug 20, 2020
Just to give you an example of the pain I have to go through each time this happens:
//cc Daniel Rosenwasser (@DanielRosenwasser)
DanielRosenwasser commentedon Aug 20, 2020
Benjamin Pasero (@bpasero) Yeah, I know, this is painful. We had a sort of mixed discussion on this.
The problem is that there's no way to know until after you've used a type that it's wrong. In the case of
Event, you can imagine a quick fix to suggest another type where the heuristic is "this one takes type arguments, this one doesn't". That's a potentially reasonable one, and I was personally not against it, but a few people in the editor sync felt like that could potentially be noisy if we suggested the wrong type.In the case of Alexandru Dima (@alexdima)'s example, there's no way until any arbitrary operation to know that the type is "wrong"; even if you can figure that out, figuring out which type is "right" could be expensive to do it accurately.
Now you mentioned that there's no way to auto-import
Eventbecause the global overrides it. That shouldn't be the case, but when we experimented with it in the editor sync, we noticed that a lot of the time, auto-imports are significantly deprioritized to the point where they aren't noticed.Trying it out on your codebase, I'm definitely seeing
Eventcome up (though unfortunately it looks like there are duplicates?)bpasero commentedon Aug 20, 2020
Daniel Rosenwasser (@DanielRosenwasser) ah yeah good point about the import when you type the name, that helps. I think I often just copy this over from an interface and then miss the suggested auto imports.