Skip to content

Commit 850c2c6

Browse files
committed
fix: intersect __VLS_PublicProps on demand
1 parent 81854db commit 850c2c6

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,16 @@ export function* generateScriptSetup(
5555
+ ` __VLS_setup = (async () => {${newLine}`;
5656
yield* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, undefined);
5757

58-
const emitTypes: string[] = [];
58+
const propTypes: Code[] = [];
59+
if (ctx.generatedPropsType) {
60+
propTypes.push(`__VLS_PublicProps`);
61+
}
62+
if (scriptSetupRanges.defineEmits || scriptSetupRanges.defineModel.length) {
63+
propTypes.push(`__VLS_EmitProps`);
64+
}
65+
propTypes.push(`Partial<__VLS_InheritedAttrs>`);
5966

67+
const emitTypes: Code[] = [];
6068
if (scriptSetupRanges.defineEmits) {
6169
emitTypes.push(`typeof ${scriptSetupRanges.defineEmits.name ?? '__VLS_emit'}`);
6270
}
@@ -65,11 +73,7 @@ export function* generateScriptSetup(
6573
}
6674

6775
yield `return {} as {${newLine}`
68-
+ ` props: ${ctx.localTypes.PrettifyLocal}<${
69-
scriptSetupRanges.defineEmits || scriptSetupRanges.defineModel.length
70-
? `__VLS_EmitProps & `
71-
: ``
72-
}__VLS_PublicProps & Partial<__VLS_InheritedAttrs>> & ${
76+
+ ` props: ${ctx.localTypes.PrettifyLocal}<${propTypes.join(' & ')}> & ${
7377
options.vueCompilerOptions.target >= 3.4
7478
? `import('${options.vueCompilerOptions.lib}').PublicProps`
7579
: options.vueCompilerOptions.target >= 3

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ export default _default;
8484
8585
exports[`vue-tsc-dts > Input: generic/component.vue, Output: generic/component.vue.d.ts 1`] = `
8686
"declare const __VLS_export: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
87-
props: __VLS_PrettifyLocal<{
88-
"onUpdate:title"?: (value: string) => any;
89-
onBar?: (data: number) => any;
90-
} & ({
87+
props: __VLS_PrettifyLocal<({
9188
foo: number;
9289
} & {
9390
title?: string;
94-
}) & Partial<{}>> & import("vue").PublicProps;
91+
}) & {
92+
"onUpdate:title"?: (value: string) => any;
93+
onBar?: (data: number) => any;
94+
} & Partial<{}>> & import("vue").PublicProps;
9595
expose(exposed: import("vue").ShallowUnwrapRef<{
9696
baz: number;
9797
}>): void;
@@ -115,14 +115,14 @@ type __VLS_PrettifyLocal<T> = {
115115
116116
exports[`vue-tsc-dts > Input: generic/custom-extension-component.cext, Output: generic/custom-extension-component.cext.d.ts 1`] = `
117117
"declare const __VLS_export: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
118-
props: __VLS_PrettifyLocal<{
119-
"onUpdate:title"?: (value: string) => any;
120-
onBar?: (data: number) => any;
121-
} & ({
118+
props: __VLS_PrettifyLocal<({
122119
foo: number;
123120
} & {
124121
title?: string;
125-
}) & Partial<{}>> & import("vue").PublicProps;
122+
}) & {
123+
"onUpdate:title"?: (value: string) => any;
124+
onBar?: (data: number) => any;
125+
} & Partial<{}>> & import("vue").PublicProps;
126126
expose(exposed: import("vue").ShallowUnwrapRef<{
127127
baz: number;
128128
}>): void;
@@ -326,7 +326,7 @@ export default _default;
326326
`;
327327
328328
exports[`vue-tsc-dts > Input: reference-type-model/component.vue, Output: reference-type-model/component.vue.d.ts 1`] = `
329-
"type __VLS_PublicProps = {
329+
"type __VLS_ModelProps = {
330330
/**
331331
* required number modelValue
332332
*/
@@ -361,7 +361,7 @@ declare const __VLS_export: import("vue").DefineComponent2<{
361361
directives: {};
362362
provide: {};
363363
expose: string;
364-
__typeProps: __VLS_PublicProps;
364+
__typeProps: __VLS_ModelProps;
365365
__typeEmits: __VLS_ModelEmit;
366366
__typeRefs: {};
367367
__typeEl: any;

0 commit comments

Comments
 (0)