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

[babel-plugin] TypeScript types are wrong #889

Open
jfirebaugh opened this issue Feb 11, 2025 · 3 comments
Open

[babel-plugin] TypeScript types are wrong #889

jfirebaugh opened this issue Feb 11, 2025 · 3 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@jfirebaugh
Copy link

Describe the issue

The resolved types use export default where the JavaScript file appears to use module.exports =. This will cause TypeScript under the node16 module mode to think an extra .default property access is required, but that will likely fail at runtime.

Expected behavior

These types should use export = instead of export default.

Steps to reproduce

See https://arethetypeswrong.github.io/?p=%40stylexjs%2Fbabel-plugin%400.10.1

Test case

No response

Additional comments

No response

@jfirebaugh jfirebaugh added the bug Something isn't working label Feb 11, 2025
@nmn nmn added the good first issue Good for newcomers label Feb 15, 2025
@zaydek
Copy link

zaydek commented Feb 26, 2025

Just noticed this myself. Thanks, also following this issue.

@RavenColEvol
Copy link
Contributor

I spent some time understanding this issue, here are my findings
Since output generated is in cjs format it results in module.exports output. d.ts file should have typescript export = instead of export default since output is cjs.

The functionality which generates the types today ( .js -> .flow -> .d.ts ) there is no way for us to tell translateFlowDefToTSDef to use export = instead of export default

I tried changing export in index.js from export default to common js module.exports but it throws error in translateFlowDefToTSDef method.

@jfirebaugh @nmn

@nmn
Copy link
Contributor

nmn commented Mar 3, 2025

This is a bug in the flow-api-translator package due to differences in how Flow and Typescript.

The easiest fix would be to add a manual .d.ts file. Our script already prioritize those when they exist.

@necolas necolas changed the title Types are wrong for @stylexjs/babel-plugin [babel-plugin] TypeScript types are wrong Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants