Skip to content

Conversation

@henryqdineen
Copy link
Contributor

What changed / motivation ?

In ce530d0 I pushed a fix for a TypeScript error that we were seeing.

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$$;
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I'm assuming most other's were not hitting this if they set skipLibCheck: true. The v0.16.3 release fixed the error and our StyleX integration works as expected.

I was reading through old issues I discovered #889 and the attempted fix (#924). I think my commit ultimately reverted their fix and likely caused a regression for some people. See: https://arethetypeswrong.github.io/?p=%40stylexjs%2Fbabel-plugin%400.16.3

My fix in this PR is to go back to using export = but use a namespace so we don't run into the "An export assignment cannot be used in a module with other exported elements" error. This commit also corrects the Rule type and config argument for processStylexRules, which have changed since this file was introduced.

Sorry for the regression. Thanks!

Linked PR/Issues

#889

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 Nov 12, 2025
declare const $$EXPORT_DEFAULT_DECLARATION$$: StyleXTransformObj;
export default $$EXPORT_DEFAULT_DECLARATION$$;

declare namespace styleXTransform {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we avoid using a namespace here? Other than that the changes look good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @nmn. I was following this advice from the DefinitelyTyped README. Do you have a recommended solution without a namespace?

When the implementation package uses module.exports = ..., the DefinitelyTyped package should use export =, not export default. (Alternatively, if the module.exports is just an object of named properties, the DefinitelyTyped package can use a series of named exports.) The most common obstacle to correcting this problem is confusion about how to export types in addition to the primary export. For example, assume these types are incorrectly using export default:

export interface Options {
    // ...
}
export default function doSomething(options: Options): void;

Changing the export default to an export = creates an error:

export interface Options {
    // ...
}
declare function doSomething(options: Options): void;
export = doSomething;
// ^^^^^^^^^^^^^^^^^
// Error: An export assignment cannot be used in a module with other exported elements.

To fix this, move the types inside a namespace with the same name as the function:

declare namespace doSomething {
    export interface Options {
        // ...
    }
}
declare function doSomething(options: doSomething.Options): void;
export = doSomething;

@henryqdineen henryqdineen requested a review from nmn December 1, 2025 21:08
legacyDisableLayers?: boolean;
},
): string;
export type StyleXTransformObj = Readonly<{
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if you can use this type and use the export = syntax to make it work with cjs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't seem to find a way to do it with running in to "An export assignment cannot be used in a module with other exported elements.(2309)"

# Conflicts:
#	packages/typescript-tests/package.json
@henryqdineen henryqdineen force-pushed the hqd-fix-ts-regression branch from a948c05 to 2c43f21 Compare December 3, 2025 14:48
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