Skip to content
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

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions packages/language-core/lib/codegen/script/styleModulesType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ export function* generateStyleModulesType(
name,
'main',
offset + 1,
codeFeatures.all
codeFeatures.navigation
];
}
else {
yield name;
}
yield `: Record<string, string> & ${ctx.localTypes.PrettifyLocal}<{}`;
yield `: `;
if (!options.vueCompilerOptions.strictCssModules) {
yield `Record<string, string> & `;
}
yield `${ctx.localTypes.PrettifyLocal}<{}`;
for (const className of style.classNames) {
yield* generateCssClassProperty(
i,
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 @@ -32,6 +32,7 @@ export interface VueCompilerOptions {
checkUnknownProps: boolean;
checkUnknownEvents: boolean;
checkUnknownComponents: boolean;
strictCssModules: boolean;
skipTemplateCodegen: boolean;
fallthroughAttributes: boolean;
dataAttributes: string[];
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 @@ -265,6 +265,7 @@ export function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTempla
checkUnknownProps: strictTemplates,
checkUnknownEvents: strictTemplates,
checkUnknownComponents: strictTemplates,
strictCssModules: false,
skipTemplateCodegen: false,
fallthroughAttributes: false,
dataAttributes: [],
Expand Down
5 changes: 5 additions & 0 deletions packages/language-core/schemas/vue-tsconfig.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
"default": false,
"markdownDescription": "Check unknown components. If not set, uses the 'strictTemplates' value."
},
"strictCssModules": {
"type": "boolean",
"default": false,
"markdownDescription": "Strict CSS modules type-checking."
},
"skipTemplateCodegen": {
"type": "boolean",
"default": false,
Expand Down
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>