Skip to content

Commit

Permalink
feat: update component type
Browse files Browse the repository at this point in the history
  • Loading branch information
agileago committed Dec 9, 2021
1 parent 83ba65b commit 9debbad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions example/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,14 @@ interface FooProps {
value?: string
'onUpdate:value'?: (value: string) => void
slots: {
default(name: string): VNodeChild
item(): VNodeChild
}
}

class Foo extends VueComponent<FooProps> {
render() {
this.context.slots.default?.('aaa')
return undefined
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,23 @@ export interface Hanlder {
handler: (targetThis: any) => void
}

type DefaultSlots = {
default(): VNodeChild
}

type MixDefaultSlots<T extends {}> = 'default' extends keyof T ? {} : DefaultSlots

// 处理tsx slots 类型问题
export type WithVSlots<T extends {}> = {
'v-slots'?: 'slots' extends keyof T
? Partial<T['slots'] & { $stable: boolean; default(): VNodeChild }>
? Partial<T['slots'] & { $stable: boolean } & MixDefaultSlots<T['slots']>>
: Partial<{ $stable: boolean; default(): VNodeChild }>
}

export type WithSlotTypes<T extends {}> = Omit<SetupContext, 'slots'> & {
slots: 'slots' extends keyof T ? Partial<T['slots'] & { default(): VNodeChild }> : Partial<{ default(): VNodeChild }>
slots: 'slots' extends keyof T
? Partial<T['slots'] & MixDefaultSlots<T['slots']>>
: Partial<{ default(): VNodeChild }>
}

type ModelProps<T extends {}> = Exclude<
Expand Down

0 comments on commit 9debbad

Please sign in to comment.