Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in TypeScript types: cannot import default in Node16 or NodeNext resolution #21

Open
JoshuaKGoldberg opened this issue Dec 16, 2024 · 0 comments

Comments

@JoshuaKGoldberg
Copy link

Describe the bug

With the TSConfig module set to Node16 or NodeNext, trying to call the package's default-imported function gives:

This expression is not callable.
  Type 'typeof import("file:///node_modules/throttled-queue/dist/throttledQueue")' has no call signatures.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://www.typescriptlang.org/play/?target=99&moduleResolution=99&module=199#code/JYWwDg9gTgLgBDAFlCMYBsCmATAigV00LgDMUQ4ByJFNLbAWgEdDDKBuAKE5tQxwJFMACgCMAGjgAmAJTsgA
  2. Observe errors

Alternately, run npx @arethetypeswrong/cli --pack in the repository after running tsc.

Expected behavior

Copying the output from ATTW:

❓ The JavaScript appears to set both module.exports and module.exports.default for improved compatibility, but the types only reflect the latter (by using export default). This will cause TypeScript under the node16 module mode to think an extra .default property access is required, which will work at runtime but is not necessary. These types should export = an object with a default property instead of using export default. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/MissingExportEquals.md


┌───────────────────┬───────────────────────┐
│                   │ "throttled-queue"     │
├───────────────────┼───────────────────────┤
│ node10            │ ❓ Missing `export =` │
├───────────────────┼───────────────────────┤
│ node16 (from CJS) │ ❓ Missing `export =` │
├───────────────────┼───────────────────────┤
│ node16 (from ESM) │ ❓ Missing `export =` │
├───────────────────┼───────────────────────┤
│ bundler           │ ❓ Missing `export =` │
└───────────────────┴───────────────────────┘

Additional context

I normally fix this in .ts files with something like :

throttledQueue.default = throttledQueue;
export = throttledQueue;

Would you accept that as a PR?

P.S. throttled-queue is really handy, thanks for the package! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant