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

Package does not pass AreTheTypesWrong #70

Open
jakebailey opened this issue Dec 2, 2024 · 4 comments
Open

Package does not pass AreTheTypesWrong #70

jakebailey opened this issue Dec 2, 2024 · 4 comments

Comments

@jakebailey
Copy link

See: https://arethetypeswrong.github.io/?p=eslint-plugin-react-refresh%400.4.16

The package is bundled, and ends with:

var src_default = { rules, configs };
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  configs,
  rules
});

This means that the output dts file should actually read export = _default;, not export default _default;, since an export named default does not actually exist at runtime.

I noticed this on DT, which previously held types for this package (but will have to be deleted now that you're doing it): https://github.com/DefinitelyTyped/DefinitelyTyped/actions/runs/12118993180/job/33784693075#step:12:2663

@jakebailey
Copy link
Author

jakebailey commented Dec 2, 2024

Er, sorry, misread esbuild's output.

var src_exports = {};
__export(src_exports, {
  configs: () => configs,
  default: () => src_default,
  rules: () => rules
});
module.exports = __toCommonJS(src_exports);

I think it actually needs export = _default and export { _default as default }?

@jakebailey
Copy link
Author

jakebailey commented Dec 2, 2024

I should really just defer to the ATTW message 😅

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.

@ArnaudBarre
Copy link
Owner

Oh I didn't know someone published types for this package.
I'll update the suggested syntax

@jakebailey
Copy link
Author

My suggestion is probably wrong; you may need to declare a different type instead that's an object type with a default prop and not mix syntax. I think TS will error?

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

2 participants