-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
TypeScript 4.4 allows named imports of methods, calling them unbound #46027
Comments
You can’t call [alt text]
It was a mistake that it worked before 4.4, and it’s working as expected now. See #45189 for more discussion. |
@andrewbranch holy crap, that's... really not what I was expecting. What is the TL;DR solution for this? |
Well, I should add that the real expected behavior is that we error when you import |
The import you want to write is import process from "process"; and then call |
Thanks for that sample: I actually did that in my branch and indeed the code works with all versions of It'd be a huge help if you could make 4.4 emit a warning for this situation. I suspect every non-trivial backend typescript user is about to be bit by this issue. |
Also: thanks to you and your team for TypeScript: y'all deserve a heap of kudos. 💯 |
I’m actually going to change the title of your issue so we can keep it open tracking the lack of error. I honestly expected this to be a massive problem in 4.4, but we’ve heard fairly little noise about it so far. We would obviously like to be able to issue an error for imports that are going to break calls, but we simply don’t have enough information to know what’s going to break when looking at most |
If I'm going to dream: hoo boy would it be sweet to add a TS/JS refactoring that was "replace named imports" |
WOW NEAT. That refactoring is What do I need to feed it to make it happy? (edit: the refactoring you listed wasn't disabled: it's not there, even on typescript@next. What build are you running?) (second edit: that refactor action doesn't actually help. See #46034 (comment)) |
I think you just have to actually select the whole statement. |
(is there docs or source I can look at maybe?) |
I’m not sure, it actually works for me if my cursor is anywhere on the statement. Can you file a new issue? |
Sure, of course. On what project? (vscode or tsc?) |
TypeScript. |
Me and my team also hit this issue. Our automated CI merged the update of Typescript to 4.4.3 automatically because all checks succeeded including build, tests etc. A few days (😅) later we noticed that our application has been in a crash loop since it was a runtime problem and not a transpile time problem. |
Bug Report
🕗 Version & Regression Information
When did you start seeing this bug occur?
TypeScript 4.4
If possible, please try testing the nightly version of TS to see if it's already been fixed.
Nope. 4.5.0-dev.20210923 emits the same .js as 4.4.3.
This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________I was unable to test this on prior versions because _______⏯ Playground Link
Playground renders correct javascript.
💻 Code
I've reproduced the issue in this repository: https://github.com/mceachen/ts44-event-typeerror
The first commit uses TypeScript 4.3.5, and
tsc --init
with no edits. I also committed the javascript file emitted bytsc
.The second commit just upgrades TypeScript to 4.4.3, rebuilds the yarn.lock, and recompiles. The invalid javascript is visible:
🙁 Actual behavior
With both node 14.17.6 and 16.10.0, the same error emits:
🙂 Expected behavior
What I saw with TypeScript 4.3, which didn't have the
(0,
prefix in front of every method call.The text was updated successfully, but these errors were encountered: