question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSS Modules with TypeScript: css-modules-typescript-loader

See original GitHub issue

TypeScript users are flying blind when they import a CSS module. For example, if they type styles.foo they have no idea if .foo actually exists in the CSS module without manually checking the file.

This is not a great TypeScript experience.

I propose adding the css-modules-typescript-loader (or something similar) to emit type declarations for CSS modules on the fly.

It could be as simple as this:

  const loaders = [
    require.resolve('style-loader'),
    ...(useTypeScript && cssOptions.modules
      ? require.resolve('css-modules-typescript-loader')
      : []
    ),

What do you think?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:9
  • Comments:53 (23 by maintainers)

github_iconTop GitHub Comments

5reactions
Hotellcommented, Jan 8, 2019

I put down quick gist for anyone reading this issue, if they desperately need this feature without ejecting 😃

https://gist.github.com/Hotell/01035a3ec202245d6b97937444140877

I can send PR to update docs if you’re willing to accept this 😃

thanks!

4reactions
mrmckebcommented, Nov 16, 2018

Hi @jedmao and @Timer, I’ve completed the plugin and wanted to get your thoughts on it. I need to:

  • Write some E2E tests (it has basic coverage now).
  • Improve docs (for example VSCode has an option to add the plugin via VSCode’s settings).

You can find it here: https://www.npmjs.com/package/typescript-plugin-css-modules

This weekend I’ll create a PR for create-react-app with this included.

Read more comments on GitHub >

github_iconTop Results From Across the Web

css-modules-typescript-loader - npm
Webpack loader to create TypeScript declarations for CSS Modules. Latest version: 4.0.1, last published: 2 years ago.
Read more >
How to use CSS Modules with TypeScript and webpack
Using CSS Modules with TypeScript is not as obvious as with JavaScript. ... a drop-in replacement for css-loader that generates typings for CSS...
Read more >
seek-oss/css-modules-typescript-loader - GitHub
Webpack loader to create TypeScript declarations for CSS Modules. Emits TypeScript declaration files matching your CSS Modules in the same location as your ......
Read more >
How to import CSS modules with Typescript, React and ...
Typescript compiler will understand that css import will be module with properties ... Loader will generate Css modules typings file ( component.css.d.ts ) ......
Read more >
Increasing the Value of CSS Modules with Typescript
1. Create a New Project · 2. Rename CSS Files · 3. Import CSS Modules · 4. Add Typescript Plugin · 5. Use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found