Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types of CSS modules #121

Open
TeoTN opened this issue Mar 12, 2021 · 3 comments
Open

Types of CSS modules #121

TeoTN opened this issue Mar 12, 2021 · 3 comments

Comments

@TeoTN
Copy link

TeoTN commented Mar 12, 2021

It's not clear to me how currently should types be declared for CSS modules.
For the context, I'm using Gatsby v3 with TypeScript and an example import would be:

import { Header } from './header.module.css';

However, the old style index.d.ts I had won't be suitable anymore since default exports were replaced with tree-shakeable variables:

declare module '*.module.css' {
  const value: { [className: string]: string };
  export default value;
}

That pretty much now ends up in this error:

 Module '"*.module.css"' has no exported member 'Header'. Did you mean to use 'import Header from "*.module.css"' instead?

I'm not sure how this can be handled in the latest version?

@jamesthomsondev
Copy link

@TeoTN Running into the same issue, were you able to resolve this?

@TeoTN
Copy link
Author

TeoTN commented Nov 1, 2021

@getreworked Well, no, not really. From what I see in that repo I ended up with empty module declaration

declare module '*.module.css';

@IanVS
Copy link

IanVS commented May 13, 2022

There is https://github.com/Quramy/typed-css-modules, for anyone who might come across this issue. I use it in CI to generate types for my css modules before running my type checks.

And I use https://github.com/mrmckeb/typescript-plugin-css-modules in VSCode to check the types as I'm editing. This combo has served me well for the last year or so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants