microsoft / microsoft/TypeScript
In a JS file, using module.exports in a file changes the type of module from NodeModule to typeof import("...")
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
Bug Report
When using a JS file with @types/node, the type of module changes from NodeModule to something strange (typeof import("/sandbox/not_working");) after including a line like module.exports = {}.
🔎 Search Terms
module.exports, NodeModule, typeof import
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about
4.2.3
⏯ Playground Link
CodeSandbox link with relevant code
💻 Code
/// <reference types="node"/>
// INFO: This is JS
/**
* @param {NodeModule} aModule
*/
function createLogger(aModule) {}
createLogger(module); // INFO: module here is triggering the error.
// INFO: THIS LINE BREAKS IT
module.exports = {};
🙁 Actual behavior
var module: {
"\"/sandbox/not_working\"": typeof import("/sandbox/not_working");
}
Argument of type '{ "\"/sandbox/not_working\"": typeof import("/sandbox/not_working"); }'
is not assignable to parameter of type 'NodeModule'.
Type '{ "\"/sandbox/not_working\"": typeof import("/sandbox/not_working"); }'
is missing the following properties from type 'NodeModule': require, id, filename, loaded, and 3 more.
ts(2345)
🙂 Expected behavior
I expected module to always be of type NodeModule.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem CodeSandbox-Beispiel und seiner not_working.js-Reproduktion und konzentriere dich darauf, wie module.exports = {} den abgeleiteten Typ von module ändert. Bestätige das erwartete NodeModule-Verhalten und füge einen Regressionstest hinzu, der zeigt, dass createLogger(module) nach der Exportzuweisung weiterhin gültig bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100