stylex icon indicating copy to clipboard operation
stylex copied to clipboard

[babel-plugin] TypeScript types are wrong

Open jfirebaugh opened this issue 10 months ago • 4 comments

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 avatar Feb 11 '25 00:02 jfirebaugh

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

zaydek avatar Feb 26 '25 17:02 zaydek

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

RavenColEvol avatar Mar 02 '25 15:03 RavenColEvol

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.

nmn avatar Mar 03 '25 04:03 nmn

I created another slight-related issue because the TypeScript types appear to be super invalid beyond what is discussed here.

https://github.com/facebook/stylex/issues/969

AlexanderOMara avatar Apr 01 '25 23:04 AlexanderOMara