Replies: 3 comments 3 replies
-
Bah I love the idea of this and agree it's more than a nice-to-have. But I wish the implementation didn't require putting fake I wonder if we could recommend this for now: https://github.com/mrmckeb/typescript-plugin-css-modules. This would get you the IDE feedback AND supports Less/Sass/Stylus without any added complexity on our end. I also wonder if that plugin actually does work with the TypeScript CLI. Since |
Beta Was this translation helpful? Give feedback.
-
Using declaration files only partially solves the problem. It doesn't provide functionality like find references, rename, go to definition, for class names. I would love to see a solution which also solves those problems. |
Beta Was this translation helpful? Give feedback.
-
@robpalme gave a good idea on Twitter: https://twitter.com/robpalmer2/status/1322226084381949952 |
Beta Was this translation helpful? Give feedback.
-
As users of CSS Modules and TypeScript ourselves, I’d love to add support for it.
Currently if you tried to run:
TypeScript would throw an error because there are no types for this module. A few just put a blanket module declaration that types
.css
files toany
, but for people that want TypeScript to do its job and tell them if they’ve misspelled a class name, it’s tough.It’s possible in webpack with things like typings-for-css-module-loader, which the popularity of the project should speak to how many people rely on solutions like this.
The basic idea is: for every
.module.css
file in the project, a*.module.css.d.ts
file is generated alongside it, insrc
. This is all TypeScript needs to see into the scoped classes.What would adding support for this look like?
To be clear, I think it’s more than a “nice to have.” I truly think it’s a blocker for people wanting to use TypeScript and CSS Modules, two very common paradigms.
Should the
.d.ts
generation happen as part of the build pipeline? Could it be enabled by default (and could we be smarter about it, i.e. only generate these if TS is detected in your project)? As someone that’s set this up before, it’d be great to handle this out-of-the-box, since Snowpack offers support for both out-of-the-box; just not combined.Beta Was this translation helpful? Give feedback.
All reactions