typescript-plugin-css-modules
typescript-plugin-css-modules copied to clipboard
Using `import * as styles` does not result in a type error at use
Describe the bug
The correct way of importing modules in a .ts
or .tsx
file is import styles from "./my-styles.modules.css";
, however if I accedentally do import * as styles from "./my-styles.modules.css";
then I don't get a type error in VsCode, I only get one when I run tsc
(because I have a separate mock for tsc).
Same issue, even if i would like to being able to import css modules using import * as styles
since is now the "recommended" way to import them (along side named exports, which is not always possible).
If you want to get an error, you have to add namedExports: false
:
{
"plugins": [{
"name": "typescript-plugin-css-modules",
"options": {
"namedExports": false
}
}]
}
It will work if you disable allowSyntheticDefaultImports
config in tsconfig.json
I'll close this off as @ArthurStam's suggestions look right here.
These syntaxes are all supported, and we've tried to land on a good set of sensible defaults here - but every project is different, and it's hard to find the right defaults for everyone.
It also works if I leave allowSyntheticDefaultImports
as true
as well. Which is good because some libraries require having that configuration on to use.