Skip to content

[ENHANCEMENT] ship type declarations for the CSS entry points - #477

Open
zhuje wants to merge 1 commit into
mainfrom
zhuje/ui-customization-css-type-stubs
Open

zhuje wants to merge 1 commit into
mainfrom
zhuje/ui-customization-css-type-stubs

Conversation

@zhuje

@zhuje zhuje commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Description

Consumers that write import '@perses-dev/design-tokens/css' (or @perses-dev/components/next/css) get TS2882: Cannot find module or type declarations for side-effect import under moduleResolution: bundler. The exports entries point at bare .css files with no .d.ts, and a consumer-side declare module '*.css' cannot match a suffix-less specifier, so every app and plugin currently has to hand-write a declare module '@perses-dev/…/css' stub (see ui/app/src/css.d.ts in perses/perses#4804).

This PR makes the packages own that declaration:

  • design-tokens/src/css/index.d.ts and components/src/next/css/index.d.ts: empty export {} stubs.
  • design-tokens/package.json: ./css, ./css/layers, ./css/reset, ./css/tokens, ./css/semantic become { "types": "./dist/css/index.d.ts", "default": "./dist/css/<name>.css" }; build:css also copies src/css/*.d.ts.
  • components/package.json: ./next/css and the three ./next/primitives/system/*.css entries get the same { types, default } shape; build:next-css also copies src/next/css/*.d.ts.
  • .swcrc: exclude \.d\.ts$ so swc stops compiling declaration files into empty dist/**/*.d.js artifacts (this already happened for theme/types/*.d.ts, next/css.d.ts and client/src/types/globals.d.ts).

Runtime resolution is unchanged: bundlers still pick default and load the same CSS files. Bare entry points type-check in consumers without local stubs, while a typo such as @perses-dev/design-tokens/css/missing still errors.

Validation:

Command Result
npm run build -w design-tokens -w components pass; dist/css/index.d.ts and dist/next/css/index.d.ts present, no .d.js emitted
Throwaway consumer (moduleResolution: bundler, no local stubs) importing all 5 bare entry points + system/layout.css pass; bogus css/missing import still fails with TS2882
npm run lint -w design-tokens -w components pass (pre-existing warnings only)
npm run type-check -w design-tokens -w components pass
npm run format:check pass
make checklicense pass

Screenshots

N/A — packaging and type declarations only.

Checklist

  • Pull request has a descriptive title and context useful to a reviewer.
  • Pull request title follows the [<catalog_entry>] <commit message> naming convention using one of the
    following catalog_entry values: FEATURE, ENHANCEMENT, BUGFIX, BREAKINGCHANGE, DOC,IGNORE.
  • All commits have DCO signoffs.

UI Changes

  • Changes that impact the UI include screenshots and/or screencasts of the relevant changes.
  • Code follows the UI guidelines.
  • E2E tests are stable and unlikely to be flaky.
    See e2e docs for more details. Common issues include:
    • Is the data inconsistent? You need to mock API requests.
    • Does the time change? You need to use consistent time values or mock time utilities.
    • Does it have loading states? You need to wait for loading to complete.

Signed-off-by: Jenny Zhu <jenny.a.zhu@gmail.com>
@zhuje
zhuje requested a review from a team as a code owner December 3, 2026 22:00
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit b59873a.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant