From 1d5a411c1e3aa062aa5080432cf3f852f1583ed2 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 8 Jul 2022 15:15:22 +0800 Subject: [PATCH] fix(types): fix type inference when using components option --- types/options.d.ts | 6 +++--- types/test/v3/define-component-test.tsx | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/types/options.d.ts b/types/options.d.ts index f1db523a04..736da7ade3 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -20,7 +20,7 @@ export type Component< | typeof Vue | FunctionalComponentOptions | ComponentOptions - | DefineComponent + | DefineComponent type EsModule = T | { default: T } @@ -201,9 +201,9 @@ export interface ComponentOptions< directives?: { [key: string]: DirectiveFunction | DirectiveOptions } components?: { [key: string]: - | Component + | {} + | Component | AsyncComponent - | DefineComponent } transitions?: { [key: string]: object } filters?: { [key: string]: Function } diff --git a/types/test/v3/define-component-test.tsx b/types/test/v3/define-component-test.tsx index 1b0847a379..dc71b44e46 100644 --- a/types/test/v3/define-component-test.tsx +++ b/types/test/v3/define-component-test.tsx @@ -1115,3 +1115,26 @@ describe('functional w/ object props', () => { // @ts-expect-error ; }) + +// #12628 +defineComponent({ + components: { + App: defineComponent({}) + }, + data() { + return {} + }, + provide(): any { + return { + fetchData: this.fetchData + } + }, + created() { + this.fetchData() + }, + methods: { + fetchData() { + throw new Error('Not implemented.') + } + } +})