TypeScript 4.4 allows named imports of methods, calling them unbound
See original GitHub issueBug 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 a crash
- ✔️ This changed between versions 4.3.5 and 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:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var process_1 = require("process");
(0, process_1.addListener)("SIGINT", function (evt) {
console.log("caught SIGINT", evt);
});
console.log("GREAT SUCCESS");
🙁 Actual behavior
With both node 14.17.6 and 16.10.0, the same error emits:
node:events:425
events = target._events;
^
TypeError: Cannot read properties of undefined (reading '_events')
at _addListener (node:events:425:19)
at addListener (node:events:487:10)
at Object.<anonymous> (/home/mrm/src/ts44-event-typeerror/test.js:4:27)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
at node:internal/main/run_main_module:17:47
🙂 Expected behavior
What I saw with TypeScript 4.3, which didn’t have the (0,
prefix in front of every method call.
Issue Analytics
- State:
- Created 2 years ago
- Comments:17 (8 by maintainers)
Top Results From Across the Web
TS 4.4.0-beta: #44624 change breaks existing code ... - GitHub
Bug Report Search Terms TS 4.4 beta commonjs Version & Regression ... TypeScript 4.4 allows named imports of methods, calling them unbound #46027....
Read more >Documentation - Module Resolution - TypeScript
Traditionally, imports in Node. js are performed by calling a function named require . The behavior Node. js takes will differ depending on...
Read more >Documentation - Modules - TypeScript
Often modules extend other modules, and partially expose some of their features. A re-export does not import it locally, or introduce a local...
Read more >Documentation - TypeScript 4.7
Node.js supports a new setting in package.json called type . ... The type field in package.json is nice because it allows us to...
Read more >Documentation - TypeScript 4.9
When TypeScript first supported type-checking and compilation for JavaScript, it accidentally supported a feature called import elision. In short, if an import ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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
.d.ts
files. It’s literally not fixable for a lot of cases, so we’re still keeping an ear out and hoping that problems in the real world are few and far between.