microsoft / microsoft/TypeScript
Unsupported expando pattern in commonjs prevents parent function from being called
Open
Nobody has claimed this yet.
Bug
Domain: JavaScript
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Bug Report
From npm@7, repros at least in 4.1 and 4.3-dev. It's likely to have been around since late 3.* at least
💻 Code
// @checkjs: true
// @filename: mod1.js
module.exports.json = fetchJSON
function fetchJSON () {
}
module.exports.json.stream = fetchJSONStream
function fetchJSONStream () {
}
// @filename: test.js
const npmFetch = require('./mod1')
let u2 = npmFetch.json()
🙁 Actual behavior
Error: 'typeof json' has no call signatures.
BUT quick info for json is:
module json
(alias) function json(): void
import json
🙂 Expected behavior
no error and u2: void
Inlining fetchJSON to be module.exports.json = function fetchJSON() { } fixes the problem because it's correctly treated as a expando.
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 by running the supplied checkjs repro using mod1.js and test.js, then inspect how CommonJS export assignments and expandos are analyzed. The fix is complete when the call to npmFetch.json() produces no error and u2 is typed as void.
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