typescript-plugin-css-modules is a TypeScript language service plugin that enhances developer experience by providing type information and autocomplete for CSS Modules within IDEs. It allows developers to safely use CSS class names, including those from SCSS, Sass, Less, and Stylus files, by inferring types from their module exports. The current stable version is 5.2.0. This plugin primarily focuses on design-time support for tools that leverage TypeScript's language service, such as VS Code, rather than providing compilation-time error checking or direct CSS Module bundling/processing. Its release cadence is generally every few months for minor versions, with patch releases as needed. A key differentiator is its seamless integration with the TypeScript language service to provide strong typing and intellisense for CSS module exports, catching typos and providing auto-completion where standard TypeScript or bundler configurations might only offer generic `[key: string]: string` types.
npm install typescript-plugin-css-modulesVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates installing the plugin, configuring `tsconfig.json`, and importing CSS Modules with both default and named exports in a React component, providing type safety for class names.
Upgrade your TypeScript dependency to version 4.0.0 or higher in your `package.json` and reinstall dependencies.
Ensure your build system (Webpack, Rollup, Vite, etc.) is correctly configured to process CSS Modules at compilation time. This plugin only enhances IDE developer experience.
In VS Code, open the command palette (`Ctrl+Shift+P` or `Cmd+Shift+P`), search for 'TypeScript: Select TypeScript Version', and choose 'Use Workspace Version'.
Check the project's GitHub issues for updates on `@use` support. A temporary workaround might involve adjusting your SCSS structure or custom matchers if available, or potentially adding explicit type declarations.
If your project uses Stylus, install it: `npm install --save-dev stylus` or `yarn add -D stylus`.
1. Ensure `typescript-plugin-css-modules` is listed in `compilerOptions.plugins` in `tsconfig.json`. 2. For broader compatibility and to avoid build errors, add global type declarations for CSS modules (e.g., `declare module '*.module.css';`) in a `.d.ts` file in your project.
Verify `tsconfig.json` plugin configuration. If using VS Code, ensure it's set to 'Use Workspace Version' of TypeScript. Check for conflicting global `.d.ts` declarations that might provide a generic `[key: string]: string` type without the specific class names.
This specific issue (related to TS5 and `composite: true`) points to a bug. Refer to the project's GitHub issues (`mrmckeb/typescript-plugin-css-modules#222`) for the latest status and potential workarounds, which may involve explicit `include` patterns or plugin options.