From 2b9c84d4a86ea268a6369ffbd46cf2474f94c638 Mon Sep 17 00:00:00 2001 From: SerKo Date: Mon, 17 Nov 2025 05:51:33 +0800 Subject: [PATCH 1/9] fix: add setup return type to template ctx when `exportDefault` --- packages/language-core/lib/codegen/script/template.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/language-core/lib/codegen/script/template.ts b/packages/language-core/lib/codegen/script/template.ts index f0e2f937c7..75c4055e6f 100644 --- a/packages/language-core/lib/codegen/script/template.ts +++ b/packages/language-core/lib/codegen/script/template.ts @@ -54,6 +54,10 @@ function* generateTemplateCtx( } if (options.sfc.script?.src || options.scriptRanges?.exportDefault) { exps.push(`{} as InstanceType<__VLS_PickNotAny {}>>`); + const setupReturn = `NonNullable>`; + exps.push( + `{} as ${`import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<${setupReturn}>`}>`, + ); } else { exps.push(`{} as import('${options.vueCompilerOptions.lib}').ComponentPublicInstance`); From 22ff9eaad9574db1d0ac4b204c62042b4d0bea5d Mon Sep 17 00:00:00 2001 From: SerKo Date: Mon, 17 Nov 2025 05:57:51 +0800 Subject: [PATCH 2/9] fix: support awaitable setup --- packages/language-core/lib/codegen/script/template.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/language-core/lib/codegen/script/template.ts b/packages/language-core/lib/codegen/script/template.ts index 75c4055e6f..63ae7f3092 100644 --- a/packages/language-core/lib/codegen/script/template.ts +++ b/packages/language-core/lib/codegen/script/template.ts @@ -54,7 +54,7 @@ function* generateTemplateCtx( } if (options.sfc.script?.src || options.scriptRanges?.exportDefault) { exps.push(`{} as InstanceType<__VLS_PickNotAny {}>>`); - const setupReturn = `NonNullable>`; + const setupReturn = `NonNullable>>`; exps.push( `{} as ${`import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<${setupReturn}>`}>`, ); From a8fd37c1bf5d9592fd286c0f8a173ea243f6d89e Mon Sep 17 00:00:00 2001 From: SerKo Date: Mon, 17 Nov 2025 06:09:34 +0800 Subject: [PATCH 3/9] refactor: simplify codegen --- packages/language-core/lib/codegen/script/template.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/language-core/lib/codegen/script/template.ts b/packages/language-core/lib/codegen/script/template.ts index 63ae7f3092..85850637b6 100644 --- a/packages/language-core/lib/codegen/script/template.ts +++ b/packages/language-core/lib/codegen/script/template.ts @@ -53,11 +53,9 @@ function* generateTemplateCtx( exps.push(`globalThis`); } if (options.sfc.script?.src || options.scriptRanges?.exportDefault) { + yield `type __VLS_SelfSetupReturn = NonNullable>>>${endOfLine}` exps.push(`{} as InstanceType<__VLS_PickNotAny {}>>`); - const setupReturn = `NonNullable>>`; - exps.push( - `{} as ${`import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<${setupReturn}>`}>`, - ); + exps.push(`{} as import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<__VLS_SelfSetupReturn>`); } else { exps.push(`{} as import('${options.vueCompilerOptions.lib}').ComponentPublicInstance`); From 34028d23192d96f6360a0cf40e438c15ccaf0500 Mon Sep 17 00:00:00 2001 From: SerKo Date: Mon, 17 Nov 2025 06:12:15 +0800 Subject: [PATCH 4/9] fix: use `__VLS_ProxyRefs` and add `__VLS_PickNotAny` --- packages/language-core/lib/codegen/script/template.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/language-core/lib/codegen/script/template.ts b/packages/language-core/lib/codegen/script/template.ts index 85850637b6..9c3efac3a4 100644 --- a/packages/language-core/lib/codegen/script/template.ts +++ b/packages/language-core/lib/codegen/script/template.ts @@ -55,7 +55,7 @@ function* generateTemplateCtx( if (options.sfc.script?.src || options.scriptRanges?.exportDefault) { yield `type __VLS_SelfSetupReturn = NonNullable>>>${endOfLine}` exps.push(`{} as InstanceType<__VLS_PickNotAny {}>>`); - exps.push(`{} as import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<__VLS_SelfSetupReturn>`); + exps.push(`{} as __VLS_PickNotAny<__VLS_ProxyRefs<__VLS_SelfSetupReturn>, {}>`); } else { exps.push(`{} as import('${options.vueCompilerOptions.lib}').ComponentPublicInstance`); From 5377ddab9da93852c2a1bfac425da319a9090b74 Mon Sep 17 00:00:00 2001 From: SerKo Date: Mon, 17 Nov 2025 06:15:52 +0800 Subject: [PATCH 5/9] chore: add fixture --- .../tsc/passedFixtures/#5069/main.vue | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test-workspace/tsc/passedFixtures/#5069/main.vue diff --git a/test-workspace/tsc/passedFixtures/#5069/main.vue b/test-workspace/tsc/passedFixtures/#5069/main.vue new file mode 100644 index 0000000000..facfd9de3d --- /dev/null +++ b/test-workspace/tsc/passedFixtures/#5069/main.vue @@ -0,0 +1,18 @@ + + + From 9dfa0ef5f1da8205084318f86b097227b3d3c530 Mon Sep 17 00:00:00 2001 From: SerKo Date: Wed, 19 Nov 2025 06:25:24 +0800 Subject: [PATCH 6/9] feat: exclude `expose` from `__VLS_self` --- .../language-core/lib/codegen/globalTypes.ts | 52 +++++++++++++++++++ .../lib/codegen/script/template.ts | 11 ++-- .../language-core/lib/parsers/scriptRanges.ts | 6 +++ 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/packages/language-core/lib/codegen/globalTypes.ts b/packages/language-core/lib/codegen/globalTypes.ts index f7ecf77131..1e66089e52 100644 --- a/packages/language-core/lib/codegen/globalTypes.ts +++ b/packages/language-core/lib/codegen/globalTypes.ts @@ -42,6 +42,58 @@ export function generateGlobalTypes(options: VueCompilerOptions) { type __VLS_IsAny = 0 extends 1 & T ? true : false; type __VLS_PickNotAny = __VLS_IsAny extends true ? B : A; type __VLS_SpreadMerge = Omit & B; + type __VLS_PublicInstanceWithoutExpose = + T extends import('${lib}').CreateComponentPublicInstanceWithMixins< + infer P, + infer B, + infer D, + infer C extends import('${lib}').ComputedOptions, + infer M extends import('${lib}').MethodOptions, + infer Mixin extends import('${lib}').ComponentOptionsMixin, + infer Extends extends import('${lib}').ComponentOptionsMixin, + infer E extends import('${lib}').EmitsOptions, + infer PublicProps, + infer Defaults, + infer MakeDefaultsOptional extends boolean, + infer I extends import('${lib}').ComponentInjectOptions, + infer S extends import('${lib}').SlotsType, + infer LC extends Record, + infer Directives extends Record, + infer Exposed extends string, + infer TypeRefs extends Record, + infer TypeEl extends Element, + infer Provide extends import('${lib}').ComponentProvideOptions, + infer TypeEmits, + infer StrictEmits extends boolean, + infer Options + > + ? '' extends Exposed + ? T + : import('${lib}').CreateComponentPublicInstanceWithMixins< + P, + B, + D, + C, + M, + Mixin, + Extends, + E, + PublicProps, + Defaults, + MakeDefaultsOptional, + I, + S, + LC, + Directives, + '', + TypeRefs, + TypeEl, + Provide, + TypeEmits, + StrictEmits, + Options + > + : T; type __VLS_WithComponent = N1 extends keyof LocalComponents ? { [K in N0]: LocalComponents[N1] } : N2 extends keyof LocalComponents ? { [K in N0]: LocalComponents[N2] } : diff --git a/packages/language-core/lib/codegen/script/template.ts b/packages/language-core/lib/codegen/script/template.ts index 9c3efac3a4..b660d567fa 100644 --- a/packages/language-core/lib/codegen/script/template.ts +++ b/packages/language-core/lib/codegen/script/template.ts @@ -53,9 +53,14 @@ function* generateTemplateCtx( exps.push(`globalThis`); } if (options.sfc.script?.src || options.scriptRanges?.exportDefault) { - yield `type __VLS_SelfSetupReturn = NonNullable>>>${endOfLine}` - exps.push(`{} as InstanceType<__VLS_PickNotAny {}>>`); - exps.push(`{} as __VLS_PickNotAny<__VLS_ProxyRefs<__VLS_SelfSetupReturn>, {}>`); + if (options.scriptRanges?.componentOptions?.hasExposeOption) { + exps.push( + `{} as __VLS_PublicInstanceWithoutExpose {}>>>`, + ); + } + else { + exps.push(`{} as InstanceType<__VLS_PickNotAny {}>>`); + } } else { exps.push(`{} as import('${options.vueCompilerOptions.lib}').ComponentPublicInstance`); diff --git a/packages/language-core/lib/parsers/scriptRanges.ts b/packages/language-core/lib/parsers/scriptRanges.ts index 72788c2551..9a6a389cbf 100644 --- a/packages/language-core/lib/parsers/scriptRanges.ts +++ b/packages/language-core/lib/parsers/scriptRanges.ts @@ -21,6 +21,7 @@ export function parseScriptRanges(ts: typeof import('typescript'), ast: ts.Sourc directives: TextRange | undefined; name: TextRange | undefined; inheritAttrs: string | undefined; + hasExposeOption: boolean; } | undefined; @@ -57,6 +58,7 @@ export function parseScriptRanges(ts: typeof import('typescript'), ast: ts.Sourc let directivesOptionNode: ts.ObjectLiteralExpression | undefined; let nameOptionNode: ts.Expression | undefined; let inheritAttrsOption: string | undefined; + let hasExposeOption = false; ts.forEachChild(obj, node => { if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name)) { const name = _getNodeText(node.name); @@ -72,6 +74,9 @@ export function parseScriptRanges(ts: typeof import('typescript'), ast: ts.Sourc else if (name === 'inheritAttrs') { inheritAttrsOption = _getNodeText(node.initializer); } + else if (name === 'expose') { + hasExposeOption = true; + } } }); componentOptions = { @@ -83,6 +88,7 @@ export function parseScriptRanges(ts: typeof import('typescript'), ast: ts.Sourc directives: directivesOptionNode ? _getStartEnd(directivesOptionNode) : undefined, name: nameOptionNode ? _getStartEnd(nameOptionNode) : undefined, inheritAttrs: inheritAttrsOption, + hasExposeOption, }; } } From 99e09e07a61b0645157b45dd5fdb3e6aca619d59 Mon Sep 17 00:00:00 2001 From: SerKo Date: Wed, 19 Nov 2025 06:45:07 +0800 Subject: [PATCH 7/9] chore: update test unit --- .../tsc/passedFixtures/#5069/main.vue | 18 -------- .../tsc/passedFixtures/vue3/#5069/main.vue | 42 +++++++++++++++++++ 2 files changed, 42 insertions(+), 18 deletions(-) delete mode 100644 test-workspace/tsc/passedFixtures/#5069/main.vue create mode 100644 test-workspace/tsc/passedFixtures/vue3/#5069/main.vue diff --git a/test-workspace/tsc/passedFixtures/#5069/main.vue b/test-workspace/tsc/passedFixtures/#5069/main.vue deleted file mode 100644 index facfd9de3d..0000000000 --- a/test-workspace/tsc/passedFixtures/#5069/main.vue +++ /dev/null @@ -1,18 +0,0 @@ - - - diff --git a/test-workspace/tsc/passedFixtures/vue3/#5069/main.vue b/test-workspace/tsc/passedFixtures/vue3/#5069/main.vue new file mode 100644 index 0000000000..50eea53086 --- /dev/null +++ b/test-workspace/tsc/passedFixtures/vue3/#5069/main.vue @@ -0,0 +1,42 @@ + + + From 0b0b4d81cc2460368985f2f7954b21aeba628e12 Mon Sep 17 00:00:00 2001 From: SerKo Date: Wed, 19 Nov 2025 06:48:10 +0800 Subject: [PATCH 8/9] refactor: simplify type with `__VLS_SelfInstance` --- packages/language-core/lib/codegen/script/template.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/language-core/lib/codegen/script/template.ts b/packages/language-core/lib/codegen/script/template.ts index b660d567fa..2336de82a4 100644 --- a/packages/language-core/lib/codegen/script/template.ts +++ b/packages/language-core/lib/codegen/script/template.ts @@ -53,13 +53,12 @@ function* generateTemplateCtx( exps.push(`globalThis`); } if (options.sfc.script?.src || options.scriptRanges?.exportDefault) { + yield `type __VLS_SelfInstance = InstanceType<__VLS_PickNotAny {}>>${endOfLine}`; if (options.scriptRanges?.componentOptions?.hasExposeOption) { - exps.push( - `{} as __VLS_PublicInstanceWithoutExpose {}>>>`, - ); + exps.push(`{} as __VLS_PublicInstanceWithoutExpose<__VLS_SelfInstance>`); } else { - exps.push(`{} as InstanceType<__VLS_PickNotAny {}>>`); + exps.push(`{} as __VLS_SelfInstance`); } } else { From 7d45d4a7b7517fd3aa62414ad091ab05ba70cbd4 Mon Sep 17 00:00:00 2001 From: SerKo Date: Wed, 19 Nov 2025 07:21:46 +0800 Subject: [PATCH 9/9] chore: rename infer name --- packages/language-core/lib/codegen/globalTypes.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/language-core/lib/codegen/globalTypes.ts b/packages/language-core/lib/codegen/globalTypes.ts index c7bf1251a8..79a4e66f4a 100644 --- a/packages/language-core/lib/codegen/globalTypes.ts +++ b/packages/language-core/lib/codegen/globalTypes.ts @@ -63,9 +63,9 @@ export function generateGlobalTypes(options: VueCompilerOptions) { infer TypeRefs extends Record, infer TypeEl extends Element, infer Provide extends import('${lib}').ComponentProvideOptions, - infer TypeEmits, - infer StrictEmits extends boolean, - infer Options + infer PublicMixin, + infer PublicP, + infer PublicB > ? '' extends Exposed ? T @@ -89,9 +89,9 @@ export function generateGlobalTypes(options: VueCompilerOptions) { TypeRefs, TypeEl, Provide, - TypeEmits, - StrictEmits, - Options + PublicMixin, + PublicP, + PublicB > : T; type __VLS_WithComponent =