typescript-plugin-css-modules icon indicating copy to clipboard operation
typescript-plugin-css-modules copied to clipboard

Using `import * as styles` does not result in a type error at use

Open Nokel81 opened this issue 2 years ago • 2 comments

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).

Nokel81 avatar Jun 15 '22 16:06 Nokel81

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).

equinusocio avatar Sep 07 '22 10:09 equinusocio

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

ArthurStam avatar Sep 12 '22 18:09 ArthurStam

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.

mrmckeb avatar Dec 04 '22 00:12 mrmckeb

It also works if I leave allowSyntheticDefaultImports as true as well. Which is good because some libraries require having that configuration on to use.

Nokel81 avatar Dec 09 '22 17:12 Nokel81