Skip to content

Commit 9debbad

Browse files
committed
feat: update component type
1 parent 83ba65b commit 9debbad

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

example/main.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,14 @@ interface FooProps {
137137
value?: string
138138
'onUpdate:value'?: (value: string) => void
139139
slots: {
140+
default(name: string): VNodeChild
140141
item(): VNodeChild
141142
}
142143
}
143144

144145
class Foo extends VueComponent<FooProps> {
145146
render() {
147+
this.context.slots.default?.('aaa')
146148
return undefined
147149
}
148150
}

src/type.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,23 @@ export interface Hanlder {
2727
handler: (targetThis: any) => void
2828
}
2929

30+
type DefaultSlots = {
31+
default(): VNodeChild
32+
}
33+
34+
type MixDefaultSlots<T extends {}> = 'default' extends keyof T ? {} : DefaultSlots
35+
3036
// 处理tsx slots 类型问题
3137
export type WithVSlots<T extends {}> = {
3238
'v-slots'?: 'slots' extends keyof T
33-
? Partial<T['slots'] & { $stable: boolean; default(): VNodeChild }>
39+
? Partial<T['slots'] & { $stable: boolean } & MixDefaultSlots<T['slots']>>
3440
: Partial<{ $stable: boolean; default(): VNodeChild }>
3541
}
3642

3743
export type WithSlotTypes<T extends {}> = Omit<SetupContext, 'slots'> & {
38-
slots: 'slots' extends keyof T ? Partial<T['slots'] & { default(): VNodeChild }> : Partial<{ default(): VNodeChild }>
44+
slots: 'slots' extends keyof T
45+
? Partial<T['slots'] & MixDefaultSlots<T['slots']>>
46+
: Partial<{ default(): VNodeChild }>
3947
}
4048

4149
type ModelProps<T extends {}> = Exclude<

0 commit comments

Comments
 (0)