Skip to content

CSS Modules don't work with Typescript files #740

Description

@NickBeeuwsaert

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CSShas-fixA fix is available, but may not yet be released.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions