Skip to content

Conversation

@henryqdineen
Copy link
Contributor

What changed / motivation ?

We have been using skipLibCheck: true to suppress a handful TypeScript errors (see below) coming from @stylexjs/babel-plugin and we would prefer to remove this workaround. This PR attempts to fix the issue by providing .d.ts files for the problematic modules instead of relying on flow-api-translator. This is supported by the generate-types.js script.

Maintaining the d.ts files does seem like it could be a pain so I an open to other suggestions. I have considered:

  • Rewriting the flow types so flow-api-translator generates correct TS (not sure I know Flow well enough)
  • Implementing a codemod in postProcessTSOutput()

Thanks!

Additional Context

The errors we were seeing:

node_modules/@stylexjs/babel-plugin/lib/shared/common-types.d.ts:38:3 - error TS2411: Property '$$css' of type 'string | true' is not assignable to 'string' index type 'string | null'.

38   $$css: true | string;
     ~~~~~

node_modules/@stylexjs/babel-plugin/lib/shared/stylex-define-vars.d.ts:13:4 - error TS1337: An index signature parameter type cannot be a literal type or generic type. Consider using a mapped object type instead.

13   [$$Key$$: keyof Vars]: string;
      ~~~~~~~

node_modules/@stylexjs/babel-plugin/lib/shared/stylex-create-theme.d.ts:23:5 - error TS2411: Property '$$css' of type 'true' is not assignable to 'string' index type 'string'.

23   { $$css: true; readonly [$$Key$$: string]: string },
       ~~~~~

node_modules/@stylexjs/babel-plugin/lib/index.d.ts:53:1 - error TS2309: An export assignment cannot be used in a module with other exported elements.

53 export = $$EXPORT_DEFAULT_DECLARATION$$;
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Diff of the previous generated .d.ts files to the ones added in this PR. (some changes just from prettier):

// node_modules/@stylexjs/babel-plugin/lib/index.d.ts 
@@ -39,10 +39,10 @@
   config?:
     | boolean
     | {
-        useLayers?: boolean,
-        enableLTRRTLComments?: boolean,
-        legacyDisableLayers?: boolean,
-      }
+        useLayers?: boolean;
+        enableLTRRTLComments?: boolean;
+        legacyDisableLayers?: boolean;
+      },
 ): string;
 export type StyleXTransformObj = Readonly<{
   (): PluginObj;
@@ -50,4 +50,4 @@
   processStylexRules: typeof processStylexRules;
 }>;
 declare const $$EXPORT_DEFAULT_DECLARATION$$: StyleXTransformObj;
-export = $$EXPORT_DEFAULT_DECLARATION$$;
+export default $$EXPORT_DEFAULT_DECLARATION$$;

// node_modules/@stylexjs/babel-plugin/lib/shared/common-types.d.ts 
@@ -33,10 +33,9 @@
     | string
     | Readonly<{ [$$Key$$: string]: null | string }>;
 }>;
-export type FlatCompiledStyles = Readonly<{
-  [$$Key$$: string]: string | null;
-  $$css: true | string;
-}>;
+export type FlatCompiledStyles = Readonly<
+  { [$$Key$$: string]: string | null } & { $$css: true | string }
+>;
 export type StyleXOptions = Readonly<{
   classNamePrefix: string;
   debug: null | undefined | boolean;

// node_modules/@stylexjs/babel-plugin/lib/shared/stylex-create-theme.d.ts 
@@ -20,7 +20,7 @@
   },
   options?: StyleXOptions,
 ): [
-  { $$css: true; readonly [$$Key$$: string]: string },
+  { $$css: true } & { readonly [$$Key$$: string]: string },
   { [$$Key$$: string]: InjectableStyle },
 ];
 export default styleXCreateTheme;

// node_modules/@stylexjs/babel-plugin/lib/shared/stylex-define-vars.d.ts 
@@ -10,17 +10,17 @@
 import type { InjectableStyle, StyleXOptions } from './common-types';
 import type { VarsConfig } from './stylex-vars-utils';
 type VarsKeysWithStringValues<Vars extends VarsConfig> = Readonly<{
-  [$$Key$$: keyof Vars]: string;
+  [$$Key$$ in keyof Vars]: string;
 }>;
 type VarsObject<Vars extends VarsConfig> = Readonly<
-  Omit<VarsKeysWithStringValues<Vars>, keyof ({ __varGroupHash__: string })> & {
+  Omit<VarsKeysWithStringValues<Vars>, keyof { __varGroupHash__: string }> & {
     __varGroupHash__: string;
   }
 >;
 declare function styleXDefineVars<Vars extends VarsConfig>(
   variables: Vars,
   options: Readonly<
-    Omit<Partial<StyleXOptions>, keyof ({ exportId: string })> & {
+    Omit<Partial<StyleXOptions>, keyof { exportId: string }> & {
       exportId: string;
     }
   >,

Pre-flight checklist

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 24, 2025
Copy link
Member

@mellyeliu mellyeliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine as an initial cleanup, we can explore a broader re-writing down the line

@mellyeliu mellyeliu merged commit ce530d0 into facebook:main Oct 27, 2025
6 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants