Skip to content

feat(language-core): add strictCssModules option #5164

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/language-core/lib/codegen/style/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export function* generateStyleModules(
codeFeatures.navigation,
];
}
yield `: Record<string, string> & __VLS_PrettifyGlobal<{}`;
yield `: `;
if (!options.vueCompilerOptions.strictCssModules) {
yield `Record<string, string> & `;
}
yield `__VLS_PrettifyGlobal<{}`;
if (options.vueCompilerOptions.resolveExternalStylesheets) {
yield* generateExternalStylesheets(style);
}
Expand Down
1 change: 1 addition & 0 deletions packages/language-core/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface VueCompilerOptions {
jsxSlots: boolean;
strictSlotChildren: boolean;
strictVModel: boolean;
strictCssModules: boolean;
checkUnknownProps: boolean;
checkUnknownEvents: boolean;
checkUnknownDirectives: boolean;
Expand Down
1 change: 1 addition & 0 deletions packages/language-core/lib/utils/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ export function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTempla
jsxSlots: false,
strictSlotChildren: strictTemplates,
strictVModel: strictTemplates,
strictCssModules: false,
checkUnknownProps: strictTemplates,
checkUnknownEvents: strictTemplates,
checkUnknownDirectives: strictTemplates,
Expand Down
14 changes: 10 additions & 4 deletions packages/language-core/schemas/vue-tsconfig.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
"default": false,
"markdownDescription": "Strict type constraints of `v-model`. If not set, uses the 'strictTemplates' value."
},
"strictCssModules": {
"type": "boolean",
"default": false,
"markdownDescription": "Strict type checking of CSS modules."
},
"checkUnknownProps": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -115,6 +120,11 @@
"default": false,
"markdownDescription": "Enable to support typed fallthrough attributes. Please note that enabling may significantly slow down type checking."
},
"resolveExternalStylesheets": {
"type": "boolean",
"default": false,
"markdownDescription": "https://github.com/vuejs/language-tools/pull/5136"
},
"fallthroughComponentNames": {
"type": "array",
"default": [
Expand Down Expand Up @@ -177,10 +187,6 @@
],
"markdownDescription": "https://github.com/vuejs/language-tools/issues/1038, https://github.com/vuejs/language-tools/issues/1121"
},
"experimentalResolveExternalStylesheets": {
"type": "boolean",
"default": false
},
"experimentalModelPropName": {
"type": "object",
"default": {
Expand Down
2 changes: 1 addition & 1 deletion test-workspace/tsc/passedFixtures/#5136/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../../../tsconfig.base.json",
"vueCompilerOptions": {
"experimentalResolveExternalStylesheets": true
"resolveExternalStylesheets": true
},
"include": [ "**/*" ]
}
15 changes: 15 additions & 0 deletions test-workspace/tsc/passedFixtures/vue3/cssModule/strict.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- @strictCssModules true -->

<script lang="ts" setup>
import { useCssModule } from 'vue';
import { exactType } from '../../shared';
const style = useCssModule();
exactType(style, {} as {
foo: string;
});
</script>

<style module>
.foo { }
</style>