-
Notifications
You must be signed in to change notification settings - Fork 13k
Don’t offer import fix for members of arrays or classes #35635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Arrays definitely make sense but instance type i am not so sure. do we have a repro package that causes this because of instance type? |
Nothing specific, but I can’t think of a time when it would be appropriate to import a class instance member. My original motivation was to eliminate fixes like this: But since I guess you could make the argument that if these fixes aren’t disruptive, we should leave them alone. (The array case was disruptive.) It should be noted they don’t occur for completions, only code fixes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since JS methods aren't bound I think suggesting them in a fix is a likely trap. So I think class types are correct to exclude.
// @strict: true | ||
// @esModuleInterop: true | ||
|
||
// @Filename: /array.ts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
silly question: you don't need the leading /
, do you? I never use it but see tests that do, and I have no idea what the difference is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without leading /
the array.ts
's full path will be /tests/cases/compiler
I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No you don’t, but leaving it off scares me because I don’t understand what assumptions are being made about the file system and it makes me uncomfortable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just imagining writing real files to /
and that scared me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
macOS root is no longer user-writable so the test would have failed for me 😁
Note: I find the current behaviour pretty hilarious so if unbound methods weren't such a trap I would not approve this PR. |
Notable: they're not actually unbound at runtime in our default emit, since we compile every usage to |
We could crawl DT pretty easily to figure out how many packages this affects, no? Just need to check if each module's got an |
wait, does this work for static or instance methods? I thought it was instance methods. (Yes, crawling DT would be pretty easy.) |
Whoa. I would not expect this. 😄 I don’t understand why anyone with an intermediate+ understanding of JS would expect this. I guess when I think about a named import downleveling to CommonJS, I assume |
13 packages on DT will be affected. I checked the first 6 before getting tired of doing that and feeling like I had enough info to feel good about this:
|
When a module
export =
something with an array or class instance type, this prevents import fixes for its members from showing up, e.g.Fixes #35269