Skip to content

Commit 0a3d327

Browse files
committed
refactor: remove __VLS_makeOptional
1 parent 2c87740 commit 0a3d327

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ export function generateGlobalTypes(options: VueCompilerOptions) {
155155
: T extends (...args: any) => any
156156
? T
157157
: (arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown) => void;
158-
function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
159158
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
160159
T extends new (...args: any) => any ? __VLS_FunctionalComponent<K>
161160
: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>${

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

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,16 @@ export function* generateComponent(
3232
yield `setup() {${newLine}`;
3333
const returns: Code[] = [];
3434
if (ctx.bypassDefineComponent) {
35-
yield* `const __VLS_returns = {${newLine}`;
36-
yield* generateComponentSetupReturns(scriptSetupRanges);
37-
yield `}${endOfLine}`;
38-
returns.push(`typeof __VLS_returns`);
35+
// fill $props
36+
if (scriptSetupRanges.defineProps) {
37+
const name = scriptSetupRanges.defineProps.name ?? `__VLS_props`;
38+
// NOTE: defineProps is inaccurate for $props
39+
returns.push(`typeof ${name} & { $props: Partial<typeof ${name}> }`);
40+
}
41+
// fill $emit
42+
if (scriptSetupRanges.defineEmits) {
43+
returns.push(`{ $emit: typeof ${scriptSetupRanges.defineEmits.name ?? '__VLS_emit'} }`);
44+
}
3945
}
4046
if (scriptSetupRanges.defineExpose) {
4147
returns.push(`typeof __VLS_exposed`);
@@ -73,19 +79,6 @@ export function* generateComponent(
7379
yield `})`;
7480
}
7581

76-
export function* generateComponentSetupReturns(scriptSetupRanges: ScriptSetupRanges): Generator<Code> {
77-
// fill $props
78-
if (scriptSetupRanges.defineProps) {
79-
// NOTE: defineProps is inaccurate for $props
80-
yield `$props: __VLS_makeOptional(${scriptSetupRanges.defineProps.name ?? `__VLS_props`}),${newLine}`;
81-
yield `...${scriptSetupRanges.defineProps.name ?? `__VLS_props`},${newLine}`;
82-
}
83-
// fill $emit
84-
if (scriptSetupRanges.defineEmits) {
85-
yield `$emit: ${scriptSetupRanges.defineEmits.name ?? '__VLS_emit'},${newLine}`;
86-
}
87-
}
88-
8982
export function* generateEmitsOption(
9083
options: ScriptCodegenOptions,
9184
scriptSetupRanges: ScriptSetupRanges,

0 commit comments

Comments
 (0)