From 49766bf1f1ed169719f818b2ebc7937bf4fd50ee Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Tue, 24 Nov 2020 07:24:51 +0800 Subject: [PATCH] fix(types): improve SetupContext types (#595) --- src/component/componentOptions.ts | 21 +++++++++++++++++++-- src/mixin.ts | 2 ++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/component/componentOptions.ts b/src/component/componentOptions.ts index 5f0f1508..c78decfc 100644 --- a/src/component/componentOptions.ts +++ b/src/component/componentOptions.ts @@ -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 } diff --git a/src/mixin.ts b/src/mixin.ts index 17fe2e80..0e67e4b6 100644 --- a/src/mixin.ts +++ b/src/mixin.ts @@ -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> | undefined | null @@ -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()) }