microsoft / microsoft/TypeScript
In a JS file, using module.exports in a file changes the type of module from NodeModule to typeof import("...")
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia dall'esempio CodeSandbox e dalla relativa riproduzione in not_working.js, concentrandoti su come module.exports = {} modifica il tipo inferito di module. Conferma il comportamento previsto di NodeModule e aggiungi un test di regressione che mostri che createLogger(module) rimane valido dopo l'assegnazione dell'esportazione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100