Skip to content

Commit c95737c

Browse files
committed
Update example in README.md
1 parent 33ed211 commit c95737c

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,26 @@ Imagine you have a file `~/my-project/src/component/MyComponent/myComponent.scss
149149
Adding the `typings-for-css-modules-loader` will generate a file `~/my-project/src/component/MyComponent/myComponent.scss.d.ts` that has the following content:
150150

151151
```ts
152-
export interface IMyComponentScss {
153-
"some-class": string;
154-
someOtherClass: string;
155-
"some-class-sayWhat": string;
152+
declare namespace MyComponentScssModule {
153+
export interface IMyComponentScss {
154+
"some-class": string;
155+
someOtherClass: string;
156+
"some-class-sayWhat": string;
157+
}
156158
}
157159

158-
export const locals: IExampleCss;
159-
export default locals;
160+
declare const MyComponentScssModule: MyComponentScssModule.IMyComponentScss & {
161+
/** WARNING: Only available when `css-loader` is used without `style-loader` or `mini-css-extract-plugin` */
162+
locals: MyComponentScssModule.IMyComponentScss;
163+
};
164+
165+
export = MyComponentScssModule;
160166
```
161167

162168
```ts
163-
// using default export when used with style-loader or mini-css-extract-plugin
164-
import styles from "./myComponent.scss";
169+
// using wildcard export when used with style-loader or mini-css-extract-plugin
170+
// or default export only when typescript `esModuleInterop` enabled
171+
import * as styles from "./myComponent.scss";
165172

166173
console.log(styles["some-class"]);
167174
console.log(styles.someOtherClass);
@@ -212,12 +219,6 @@ module.exports = {
212219
}
213220
};
214221
```
215-
- Ensure all the typescript files import styles as default
216-
```diff
217-
- import * as styles from './styles.css';
218-
+ import styles from './styles.css';
219-
```
220-
- Add `esModuleInterop` TypeScript compiler option if there are type errors related to default imports
221222

222223
## Support
223224

0 commit comments

Comments
 (0)