yarn create react-app app --template typescript
cd app/
yarn add -D typescript-plugin-css-modules
- In the
compilerOptions
oftsconfig.json
addtypescript-plugin-css-modules
plugin"plugins": [{ "name": "typescript-plugin-css-modules" }]
touch src/global.d.ts
- Add the following to
global.d.ts
declare module '*.module.less' {
const classes: { [key: string]: string };
export default classes;
}
declare module '*.module.css' {
const classes: { [key: string]: string };
export default classes;
}
declare module '*.module.scss' {
const classes: { [key: string]: string };
export default classes;
}
Done! You should now be able to, in your tsx
files import styles:
import styles from './File.module.css'