`vue-tsc` shows error with css modules + `noPropertyAccessFromIndexSignature`
See original GitHub issueAfter vue-tsc v0.33.3, the case below shows error when noPropertyAccessFromIndexSignature
is true
in tsconfig.
<template>
<div :class="$style.foo">foo</div>
</template>
<style module>
.foo {
color: red;
}
</style>
vue-tsc below v0.33.3 shows no error and also volar does not show any error with any version.
Reproduction
https://stackblitz.com/edit/vitejs-vite-g65tbc
Run npm run check
(which will run vue-tsc --noEmit
)
❯ npm run check
$ vue-tsc --noEmit
App.vue:2:23 - error TS4111: Property 'foo' comes from an index signature, so it must be accessed with ['foo'].
2 <div :class="$style.foo">foo</div>
~~~
Found 1 error in App.vue:2
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Error using css modules in typescript react with webpack config
Regarding to the typing, you can fix by removing namespace import since generated typing is now exporting default value.
Read more >Features | Vite
CSS Modules #. Any CSS file ending with .module.css is considered a CSS modules file. Importing such a file will return the corresponding...
Read more >vue-tsc | Yarn - Package Manager
vue-tsc. Install: npm i vue-tsc -D. Usage: vue-tsc --noEmit && vite build ... fix: auto complete randomly report [TS Error] { } and...
Read more >Increasing the Value of CSS Modules with Typescript
CSS Modules are an excellent tool for isolating application styles to the components that use them. And with the power of Typescript, ...
Read more >Getting Started with CSS Modules
js file we'll find an error when we run npm start again: That's the error that webpack will reveal if it can't find...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sapphi-red Thank you for your explanation! But since the work are a bit much, I’ll look at it later. I just change
$style
type to any for now.I digged down this a bit.
compileStyleAsync
. Note thatcompileStyle
cannot be used. But currentlygetCssClasses
requires sync functions it is not possible to use.getCssClasses
is used to get class names not only for css modules. ButcompileStyleAsync
can only get css module class names.May be it needs to split
getCssClasses
intogetCssModuleClasses
andgetCssRawClasses
(not sure whether this is a proper name)? and then changegetCssModuleClasses
to accept async functions.