Skip to content

fix: emit non-empty types for nativewind/preset - #1784

Open
TheSeydiCharyyev wants to merge 1 commit into
nativewind:v4from
TheSeydiCharyyev:TheSeydiCharyyev/fix-preset-types
Open

TheSeydiCharyyev wants to merge 1 commit into
nativewind:v4from
TheSeydiCharyyev:TheSeydiCharyyev/fix-preset-types

Conversation

@TheSeydiCharyyev

Copy link
Copy Markdown

Summary

Fixes #1330.

packages/nativewind/src/tailwind/index.ts uses module.exports = Object.assign(...), a pattern TypeScript's declaration emit can't handle — the published package ships an empty dist/tailwind/index.d.ts. Users importing nativewind/preset under checkJs: true (or from *.ts files) hit TS2306: File '.../dist/tailwind/index.d.ts' is not a module.

@danstepanov confirmed the root cause in #1330 (comment):

The published npm package has an empty (0 byte) dist/tailwind/index.d.ts. The source file (src/tailwind/index.ts) uses module.exports = Object.assign(...) which TypeScript's declaration emit can't generate types for.

Fix

Switch to the canonical TS-compatible CJS pattern:

const preset = Object.assign(
  () => { /* ... */ },
  { nativewind: true as const },
);

export = preset;
  • tsc --declaration emits a non-empty .d.ts for export = X.
  • The compiled .js still emits module.exports = preset — identical runtime shape, no breaking change for consumers.
  • as const narrows nativewind: true to a literal type, matching the manual workaround users have been writing via module augmentation.

Verification

Before fix: dist/tailwind/index.d.ts is 0 bytes.

After fix: dist/tailwind/index.d.ts contains:

declare const preset: (() => any) & {
    nativewind: true;
};
export = preset;

Compiled dist/tailwind/index.js is runtime-equivalent (module.exports = preset with the same callable + nativewind: true property).

Tests

npm test passes — 784/784 tests across 30 suites, no regressions.

The source file used `module.exports = Object.assign(...)` which TypeScript's declaration emit can't generate types for, so the published package shipped an empty `dist/tailwind/index.d.ts`. Users importing `nativewind/preset` under `checkJs: true` hit TS2306.

Switch to `const preset = Object.assign(...); export = preset;`. This pattern is correctly handled by `tsc --declaration` (emits a non-empty .d.ts), compiles to the same `module.exports = preset` runtime shape, and preserves the callable-with-property API — no breaking change for consumers.

Fixes nativewind#1330
@danstepanov danstepanov added the v4 Issue pertains to version 4 label Jul 15, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v4 Issue pertains to version 4

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants