microsoft / microsoft/TypeScript

Unsupported expando pattern in commonjs prevents parent function from being called

Open
#42,843 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.