Skip to content

Commit 5d841f4

Browse files
authored
fix(language-core): defineModel for generic component types (#5748)
1 parent d937a84 commit 5d841f4

File tree

7 files changed

+27
-6
lines changed

7 files changed

+27
-6
lines changed

packages/language-core/lib/codegen/globalTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function generateGlobalTypes(options: VueCompilerOptions) {
3232
? `import('${lib}/jsx-runtime').JSX.IntrinsicElements`
3333
: `globalThis.JSX.IntrinsicElements`
3434
};
35-
35+
var __VLS_CheckUnknownProps: ${checkUnknownProps ? '{}' : 'Record<string, unknown>'};
3636
type __VLS_Elements = __VLS_SpreadMerge<SVGElementTagNameMap, HTMLElementTagNameMap>;
3737
type __VLS_GlobalComponents = ${
3838
target >= 3.5

packages/language-core/lib/codegen/script/scriptSetup.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ export function* generateScriptSetup(
9797
+ ` & import('${options.vueCompilerOptions.lib}').AllowedComponentProps`
9898
+ ` & import('${options.vueCompilerOptions.lib}').ComponentCustomProps`
9999
: `globalThis.JSX.IntrinsicAttributes`
100-
}${endOfLine}`
100+
}${newLine}`
101+
+ ` & (typeof globalThis extends { __VLS_CheckUnknownProps: infer P } ? P : {})${endOfLine}`
101102
+ ` expose: (exposed: ${
102103
scriptSetupRanges.defineExpose
103104
? `import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<typeof __VLS_exposed>`

packages/tsc/tests/__snapshots__/dts.spec.ts.snap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ exports[`vue-tsc-dts > Input: generic/component.vue, Output: generic/component.v
6363
}) & {
6464
"onUpdate:title"?: (value: string) => any;
6565
onBar?: (data: number) => any;
66-
}> & import("vue").PublicProps;
66+
}> & import("vue").PublicProps & (typeof globalThis extends {
67+
__VLS_CheckUnknownProps: infer P;
68+
} ? P : {});
6769
expose: (exposed: import("vue").ShallowUnwrapRef<{
6870
baz: number;
6971
}>) => void;
@@ -94,7 +96,9 @@ exports[`vue-tsc-dts > Input: generic/custom-extension-component.cext, Output: g
9496
}) & {
9597
"onUpdate:title"?: (value: string) => any;
9698
onBar?: (data: number) => any;
97-
}> & import("vue").PublicProps;
99+
}> & import("vue").PublicProps & (typeof globalThis extends {
100+
__VLS_CheckUnknownProps: infer P;
101+
} ? P : {});
98102
expose: (exposed: import("vue").ShallowUnwrapRef<{
99103
baz: number;
100104
}>) => void;

test-workspace/tsc/passedFixtures/vue3.4/components/main.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ declare const ScriptSetupGenericExact: <T, >(
6464
props: {
6565
onBar?: ((data: T) => any) | undefined;
6666
foo: T;
67-
} & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps,
67+
} & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps & Record<string, unknown>,
6868
attrs: any,
6969
slots: { default?: (props: T) => any; },
7070
emit: { (e: 'bar', data: T): void; },
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<script setup lang="ts" generic="T">
2+
defineModel<T>({ required: true });
3+
</script>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script lang="ts" setup>
2+
import { ref } from 'vue';
3+
import GenericComp from './GenericComp.vue';
4+
const n = ref(0)
5+
</script>
6+
7+
<template>
8+
<GenericComp v-model="n" />
9+
<!-- @vue-expect-error -->
10+
<GenericComp />
11+
<!-- @vue-expect-error -->
12+
<GenericComp whatever="''" />"
13+
</template>

test-workspace/tsc/passedFixtures/vue3/components/main.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ declare const ScriptSetupGenericExact: <T, >(
5959
props: {
6060
onBar?: ((data: T) => any) | undefined;
6161
foo: T;
62-
} & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps,
62+
} & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps & Record<string, unknown>,
6363
attrs: any,
6464
slots: { default?: (props: T) => any; },
6565
emit: { (e: 'bar', data: T): void; },

0 commit comments

Comments
 (0)