From baa1319e37fd881967791e7ea84be73e02f8a0b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=B1=E5=90=B9=E8=89=B2=E5=BE=A1=E5=AE=88?= <85992002+KazariEX@users.noreply.github.com> Date: Fri, 25 Oct 2024 09:44:36 +0800 Subject: [PATCH] fix(language-core): intersect props of generic component with attrs (#4886) --- .../language-core/lib/codegen/script/scriptSetup.ts | 2 +- packages/tsc/tests/__snapshots__/dts.spec.ts.snap | 8 ++++---- .../generic/basic.vue | 11 +++++++++++ .../generic/child.vue | 5 +++++ .../generic/main.vue | 7 +++++++ 5 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/generic/basic.vue create mode 100644 test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/generic/child.vue create mode 100644 test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/generic/main.vue diff --git a/packages/language-core/lib/codegen/script/scriptSetup.ts b/packages/language-core/lib/codegen/script/scriptSetup.ts index a0c611e9ef..d586381247 100644 --- a/packages/language-core/lib/codegen/script/scriptSetup.ts +++ b/packages/language-core/lib/codegen/script/scriptSetup.ts @@ -68,7 +68,7 @@ export function* generateScriptSetup( } yield ` return {} as {${newLine}` - + ` props: ${ctx.localTypes.PrettifyLocal} & __VLS_BuiltInPublicProps,${newLine}` + + ` props: ${ctx.localTypes.PrettifyLocal} & __VLS_BuiltInPublicProps,${newLine}` + ` expose(exposed: import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.expose.define ? 'typeof __VLS_exposed' : '{}'}>): void,${newLine}` + ` attrs: any,${newLine}` + ` slots: __VLS_TemplateResult['slots'],${newLine}` diff --git a/packages/tsc/tests/__snapshots__/dts.spec.ts.snap b/packages/tsc/tests/__snapshots__/dts.spec.ts.snap index 4ce7c4b8fe..405127c039 100644 --- a/packages/tsc/tests/__snapshots__/dts.spec.ts.snap +++ b/packages/tsc/tests/__snapshots__/dts.spec.ts.snap @@ -5,7 +5,7 @@ exports[`vue-tsc-dts > Input: #4577/main.vue, Output: #4577/main.vue.d.ts 1`] = value: string; }; declare const _default: (__VLS_props: NonNullable>["props"], __VLS_ctx?: __VLS_PrettifyLocal>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable>["expose"], __VLS_setup?: Promise<{ - props: __VLS_PrettifyLocal & Omit<{} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, never> & { + props: __VLS_PrettifyLocal & Omit<{} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, never> & Partial<{}> & { nonGeneric: string; rows: Row[]; }> & (import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps); @@ -71,7 +71,7 @@ exports[`vue-tsc-dts > Input: events/component-generic.vue, Output: events/compo "declare const _default: (__VLS_props: NonNullable>["props"], __VLS_ctx?: __VLS_PrettifyLocal>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable>["expose"], __VLS_setup?: Promise<{ props: __VLS_PrettifyLocal & Omit<{ readonly onFoo?: (value: string) => any; - } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, "onFoo"> & {}> & (import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps); + } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, "onFoo"> & Partial<{}> & {}> & (import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps); expose(exposed: import("vue").ShallowUnwrapRef<{}>): void; attrs: any; slots: {}; @@ -93,7 +93,7 @@ exports[`vue-tsc-dts > Input: generic/component.vue, Output: generic/component.v props: __VLS_PrettifyLocal & Omit<{ readonly "onUpdate:title"?: (title: string) => any; readonly onBar?: (data: number) => any; - } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, "onUpdate:title" | "onBar"> & ({ + } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, "onUpdate:title" | "onBar"> & Partial<{}> & ({ title?: string; } & { foo: number; @@ -129,7 +129,7 @@ exports[`vue-tsc-dts > Input: generic/custom-extension-component.cext, Output: g props: __VLS_PrettifyLocal & Omit<{ readonly "onUpdate:title"?: (title: string) => any; readonly onBar?: (data: number) => any; - } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, "onUpdate:title" | "onBar"> & ({ + } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, "onUpdate:title" | "onBar"> & Partial<{}> & ({ title?: string; } & { foo: number; diff --git a/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/generic/basic.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/generic/basic.vue new file mode 100644 index 0000000000..2948bd76a6 --- /dev/null +++ b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/generic/basic.vue @@ -0,0 +1,11 @@ + + + diff --git a/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/generic/child.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/generic/child.vue new file mode 100644 index 0000000000..3e043b3148 --- /dev/null +++ b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/generic/child.vue @@ -0,0 +1,5 @@ + diff --git a/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/generic/main.vue b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/generic/main.vue new file mode 100644 index 0000000000..e2e0faaf11 --- /dev/null +++ b/test-workspace/tsc/passedFixtures/fallthroughAttributes_strictTemplate/generic/main.vue @@ -0,0 +1,7 @@ + + +