Skip to content

Commit 6646704

Browse files
serkodevKazariEX
andauthored
fix(language-core): report unused @ts-expect-error directive on components with loose props checks (#5750)
Co-authored-by: KazariEX <zinkawaii@qq.com>
1 parent f66d3d1 commit 6646704

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

packages/language-core/lib/codegen/template/context.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export function createTemplateCodegenContext(
114114
) {
115115
let variableId = 0;
116116

117-
function resolveCodeFeatures(features: VueCodeInformation) {
117+
function resolveCodeFeatures(features: VueCodeInformation): VueCodeInformation {
118118
if (features.verification && stack.length) {
119119
const data = stack[stack.length - 1]!;
120120
if (data.ignoreError) {
@@ -133,8 +133,14 @@ export function createTemplateCodegenContext(
133133
return {
134134
...features,
135135
verification: {
136-
shouldReport: () => {
137-
data.expectError!.token++;
136+
shouldReport: (source, code) => {
137+
if (
138+
typeof features.verification !== 'object'
139+
|| !features.verification.shouldReport
140+
|| features.verification.shouldReport(source, code) === true
141+
) {
142+
data.expectError!.token++;
143+
}
138144
return false;
139145
},
140146
},

packages/tsc/tests/typecheck.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ describe(`vue-tsc`, () => {
1515
"test-workspace/tsc/failureFixtures/#4569/main.vue(1,41): error TS4025: Exported variable '__VLS_export' has or is using private name 'Props'.",
1616
"test-workspace/tsc/failureFixtures/#5071/withScript.vue(1,19): error TS1005: ';' expected.",
1717
"test-workspace/tsc/failureFixtures/#5071/withoutScript.vue(2,26): error TS1005: ';' expected.",
18-
"test-workspace/tsc/failureFixtures/directives/main.vue(12,2): error TS2578: Unused '@ts-expect-error' directive.",
19-
"test-workspace/tsc/failureFixtures/directives/main.vue(4,6): error TS2339: Property 'notExist' does not exist on type '{ exist: {}; $: ComponentInternalInstance; $data: {}; $props: {}; $attrs: Data; $refs: Data; $slots: Readonly<InternalSlots>; ... 8 more ...; $watch<T extends string | ((...args: any) => any)>(source: T, cb: T extends (...args: any) => infer R ? (args_0: R, args_1: R, args_2: OnCleanup) => any : (args_0: any, args_1...'.",
20-
"test-workspace/tsc/failureFixtures/directives/main.vue(9,6): error TS2339: Property 'notExist' does not exist on type '{ exist: {}; $: ComponentInternalInstance; $data: {}; $props: {}; $attrs: Data; $refs: Data; $slots: Readonly<InternalSlots>; ... 8 more ...; $watch<T extends string | ((...args: any) => any)>(source: T, cb: T extends (...args: any) => infer R ? (args_0: R, args_1: R, args_2: OnCleanup) => any : (args_0: any, args_1...'.",
18+
"test-workspace/tsc/failureFixtures/directives/main.vue(14,6): error TS2339: Property 'notExist' does not exist on type '{ exist: {}; Comp: () => void; $: ComponentInternalInstance; $data: {}; $props: {}; $attrs: Data; $refs: Data; $slots: Readonly<InternalSlots>; ... 8 more ...; $watch<T extends string | ((...args: any) => any)>(source: T, cb: T extends (...args: any) => infer R ? (args_0: R, args_1: R, args_2: OnCleanup) => any : (a...'.",
19+
"test-workspace/tsc/failureFixtures/directives/main.vue(17,2): error TS2578: Unused '@ts-expect-error' directive.",
20+
"test-workspace/tsc/failureFixtures/directives/main.vue(20,2): error TS2578: Unused '@ts-expect-error' directive.",
21+
"test-workspace/tsc/failureFixtures/directives/main.vue(9,6): error TS2339: Property 'notExist' does not exist on type '{ exist: {}; Comp: () => void; $: ComponentInternalInstance; $data: {}; $props: {}; $attrs: Data; $refs: Data; $slots: Readonly<InternalSlots>; ... 8 more ...; $watch<T extends string | ((...args: any) => any)>(source: T, cb: T extends (...args: any) => infer R ? (args_0: R, args_1: R, args_2: OnCleanup) => any : (a...'.",
2122
]
2223
`);
2324
});

test-workspace/tsc/failureFixtures/directives/main.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
<script setup lang="ts">
2+
const exist = {};
3+
const Comp = () => {};
4+
</script>
5+
16
<template>
27
<!-- @vue-ignore -->
38
<div v-if="true">
@@ -11,8 +16,7 @@
1116

1217
<!-- @vue-expect-error -->
1318
<div v-bind="exist"></div>
14-
</template>
1519

16-
<script setup lang="ts">
17-
const exist = {};
18-
</script>
20+
<!-- @vue-expect-error -->
21+
<Comp unknown="foo" />
22+
</template>

0 commit comments

Comments
 (0)