Skip to content

Commit 112f65b

Browse files
committed
refactor(language-core): wrap __VLS_InheritedAttrs with Partial at definition
1 parent 968c00f commit 112f65b

File tree

6 files changed

+12
-10
lines changed

6 files changed

+12
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export function* generatePropsOption(
132132
const typeOptionCodes: Code[] = [];
133133

134134
if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size) {
135-
let attrsType = `Partial<__VLS_InheritedAttrs>`;
135+
let attrsType = `__VLS_InheritedAttrs`;
136136
if (hasEmitsOption) {
137137
attrsType = `Omit<${attrsType}, \`on\${string}\`>`;
138138
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function* generateScriptSetup(
6969
}
7070

7171
yield `return {} as {${newLine}`
72-
+ ` props: ${ctx.localTypes.PrettifyLocal}<__VLS_OwnProps & __VLS_PublicProps & Partial<__VLS_InheritedAttrs>> & __VLS_BuiltInPublicProps,${newLine}`
72+
+ ` props: ${ctx.localTypes.PrettifyLocal}<__VLS_OwnProps & __VLS_PublicProps & __VLS_InheritedAttrs> & __VLS_BuiltInPublicProps,${newLine}`
7373
+ ` expose(exposed: import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<${
7474
scriptSetupRanges.defineExpose ? 'typeof __VLS_exposed' : '{}'
7575
}>): void,${newLine}`

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,11 @@ function* generateInheritedAttrs(
113113
options: TemplateCodegenOptions,
114114
ctx: TemplateCodegenContext,
115115
): Generator<Code> {
116-
yield `type __VLS_InheritedAttrs = {}`;
117-
for (const varName of ctx.inheritedAttrVars) {
118-
yield ` & typeof ${varName}`;
119-
}
116+
yield `type __VLS_InheritedAttrs = ${
117+
ctx.inheritedAttrVars.size
118+
? `Partial<${[...ctx.inheritedAttrVars].map(name => `typeof ${name}`).join(` & `)}>`
119+
: `{}`
120+
}`;
120121
yield endOfLine;
121122

122123
if (ctx.bindingAttrLocs.length) {
@@ -133,7 +134,7 @@ function* generateInheritedAttrs(
133134
}
134135
yield `]${endOfLine}`;
135136
}
136-
return `import('${options.vueCompilerOptions.lib}').ComponentPublicInstance['$attrs'] & Partial<__VLS_InheritedAttrs>`;
137+
return `import('${options.vueCompilerOptions.lib}').ComponentPublicInstance['$attrs'] & __VLS_InheritedAttrs`;
137138
}
138139

139140
function* generateTemplateRefs(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ exports[`vue-tsc-dts > Input: generic/component.vue, Output: generic/component.v
6161
foo: number;
6262
} & {
6363
title?: string;
64-
}) & Partial<{}>> & import("vue").PublicProps;
64+
}) & {}> & import("vue").PublicProps;
6565
expose(exposed: import("vue").ShallowUnwrapRef<{
6666
baz: number;
6767
}>): void;
@@ -91,7 +91,7 @@ exports[`vue-tsc-dts > Input: generic/custom-extension-component.cext, Output: g
9191
foo: number;
9292
} & {
9393
title?: string;
94-
}) & Partial<{}>> & import("vue").PublicProps;
94+
}) & {}> & import("vue").PublicProps;
9595
expose(exposed: import("vue").ShallowUnwrapRef<{
9696
baz: number;
9797
}>): void;

test-workspace/tsc/passedFixtures/#5106/main.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ declare module 'vue' {
1212
}
1313
}
1414
15-
type AttrsExact = Record<string, unknown> & { class: string } & Partial<{}>;
15+
type AttrsExact = Record<string, unknown> & { class: string };
1616
1717
const attrs = useAttrs();
1818
exactType(attrs, {} as AttrsExact);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!-- @fallthroughAttributes true -->
12
<!-- @inferTemplateDollarAttrs true -->
23

34
<script setup lang="ts">

0 commit comments

Comments
 (0)