Skip to content

Commit

Permalink
fix(types): improve SetupContext types (#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Nov 23, 2020
1 parent 24bdcd2 commit 49766bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/component/componentOptions.ts
Expand Up @@ -5,10 +5,27 @@ import { ComponentInstance, ComponentRenderProxy } from './componentProxy'

export interface SetupContext {
readonly attrs: Data
readonly slots: { [key: string]: (...args: any[]) => VNode[] }
readonly slots: Readonly<{ [key in string]?: (...args: any[]) => VNode[] }>

/**
* @deprecated not avaliable in Vue 3
*/
readonly parent: ComponentInstance | null

/**
* @deprecated not avaliable in Vue 3
*/
readonly root: ComponentInstance
readonly listeners: { [key: string]: Function }

/**
* @deprecated not avaliable in Vue 3
*/
readonly listeners: { [key in string]?: Function }

/**
* @deprecated not avaliable in Vue 3
*/
readonly refs: Data

emit(event: string, ...args: any[]): void
}
Expand Down
2 changes: 2 additions & 0 deletions src/mixin.ts
Expand Up @@ -88,6 +88,7 @@ export function mixin(Vue: VueConstructor) {
def(props, '__ob__', createObserver())

// resolve scopedSlots and slots to functions
// @ts-expect-error
resolveScopedSlots(vm, ctx.slots)

let binding: ReturnType<SetupFunction<Data, Data>> | undefined | null
Expand All @@ -102,6 +103,7 @@ export function mixin(Vue: VueConstructor) {
const bindingFunc = binding
// keep currentInstance accessible for createElement
vm.$options.render = () => {
// @ts-expect-error
resolveScopedSlots(vm, ctx.slots)
return activateCurrentInstance(vm, () => bindingFunc())
}
Expand Down

0 comments on commit 49766bf

Please sign in to comment.