microsoft / microsoft/TypeScript
In a JS file, using module.exports in a file changes the type of module from NodeModule to typeof import("...")
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the CodeSandbox example and its not_working.js reproduction, focusing on how module.exports = {} changes the inferred type of module. Confirm the expected NodeModule behavior and add a regression test showing that createLogger(module) remains valid after the export assignment.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100