10000 fix(language-core): infer parameter type of union slots to be union i… · vuejs/language-tools@abb5f2b · GitHub
[go: up one dir, main page]

Skip to content

Commit abb5f2b

Browse files
authored
fix(language-core): infer parameter type of union slots to be union instead of intersection (#5475)
1 parent 68d98dc commit abb5f2b

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export function generateGlobalTypes({
164164
index: number,
165165
][];
166166
function __VLS_getSlotParameters<S, D extends S>(slot: S, decl?: D):
167-
__VLS_PickNotAny<NonNullable<D>, (...args: any) => any> extends (...args: infer P) => any ? P : any[];
167+
D extends (...args: infer P) => any ? P : any[];
168168
function __VLS_asFunctionalDirective<T>(dir: T): T extends import('${lib}').ObjectDirective
169169
? NonNullable<T['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>
170170
: T extends (...args: any) => any

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ function* generateSlotParameters(
154154
nextStart = end;
155155
}
156156
yield chunk(nextStart, expression.equalsGreaterThanToken.pos - 1);
157-
yield `] = __VLS_getSlotParameters(${slotVar}`;
157+
yield `] = __VLS_getSlotParameters(${slotVar}!`;
158158

159159
if (types.some(t => t)) {
160160
yield `, `;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script setup lang="ts">
2+
import { exactType } from '../../shared';
3+
4+
type Foo = { foo: string };
5+
type Bar = { bar: string };
6+
7+
declare const Comp: (props: {}, ctx: { slots: {
8+
foo: (props: Foo) => void;
9+
bar: (props: Bar) => void;
10+
} }) => {};
11+
</script>
12+
13+
<template>
14+
<Comp>
15+
<template v-for="name in (['foo', 'bar'] as const)" #[name]="props">
16+
{{ exactType(props, {} as Foo | Bar) }}
17+
</template>
18+
</Comp>
19+
</template>

0 commit comments

Comments
 (0)
0