Skip to content
New issue

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

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

Already on GitHub? # to your account

CSS Modules don't work with Typescript files #740

Closed
NickBeeuwsaert opened this issue Oct 15, 2020 · 0 comments · Fixed by #768
Closed

CSS Modules don't work with Typescript files #740

NickBeeuwsaert opened this issue Oct 15, 2020 · 0 comments · Fixed by #768
Labels
CSS has-fix A fix is available, but may not yet be released.

Comments

@NickBeeuwsaert
Copy link

when trying to import a CSS module in a typescript file, Typescript will give an error that it can't find the CSS module, whereas a JS module importing a CSS module works just fine. Here's a minimal reproducible example: https://gist.github.com/NickBeeuwsaert/e091e6dd45dc7c639fff91a87ee5fd7e

If you include a css-modules.d.ts file in your tsconfig.json like below, the error will go away:

/// css-modules.d.ts
declare module '*.module.css' {
    const classes: { [key: string]: string };
    export default classes;
}
/// tsconfig.json
{
"include": ["./css-modules.d.ts"]
}

This had me confused for around an hour, it would be nice if this was documented or worked out of the box. I'd be happy to work on a PR for documentation or getting this to work out of the box.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
CSS has-fix A fix is available, but may not yet be released.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants