You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After adding the type declaration, if the type error still exists, you can try to restart the current IDE, or adjust the directory where `env.d.ts` is located, making sure the TypeScript can correctly identify the type definition.
146
146
147
+
## Generate exact type definitions
148
+
149
+
Although the above method can provide the type of CSS Modules, it cannot accurately prompt which classNames are exported by a certain CSS file.
150
+
151
+
Rsbuild supports generating accurate type declarations for CSS Modules, you only need to register the [Typed CSS Modules Plugin](/plugins/list/plugin-typed-css-modules), and then execute the build, Rsbuild will generate type declaration files for all CSS Modules.
After executing the build, the `src/index.module.scss.d.ts` type declaration file will be automatically generated:
182
+
183
+
```ts title="src/index.module.scss.d.ts"
184
+
// This file is automatically generated.
185
+
// Please do not change this file!
186
+
interfaceCssExports {
187
+
'page-header':string;
188
+
pageHeader:string;
189
+
}
190
+
exportconst cssExports:CssExports;
191
+
exportdefaultcssExports;
192
+
```
193
+
194
+
Then open the `src/index.ts` file again, you will see that the `styles` object already has a exact type.
195
+
147
196
### Related configuration
148
197
149
198
In the above example, `src/index.module.scss.d.ts` is generated by compilation, you can choose to commit them to the Git repository, or you can choose to ignore them in the `.gitignore` file:
0 commit comments