mizdra / happy-css-modules

Typed, definition jumpable CSS Modules. Moreover, easy!
MIT License
213 stars 5 forks source link

Tokens loaded by `composes` are not exported #251

Closed mizdra closed 1 month ago

mizdra commented 1 month ago

Assume you have the following CSS Modules file

/* a.module.css */
.foo {
  composes: bar from "./b.module.css";
}
/* b.module.css */
.bar {
  color: blue;
}

happy-css-modules interprets that the classes a and b (internally called "token") are exported from a.module.css. Then happy-css-modules generates .d.ts like this

// a.module.css.d.ts
declare const styles:
  & Readonly<{ "foo": string }>
  & Readonly<Pick<(typeof import("./b.module.css"))["default"], "bar">>
;
export default styles;

But this is wrong: the css-loader treats only a tokens from a.module.css as if they were exported.

So we decided to change the behavior of happy-css-modules, so that it generates .d.ts like this

// a.module.css.d.ts
declare const styles:
  & Readonly<{ "foo": string }>
;
export default styles;