From: Evan You Date: Tue, 24 Dec 2019 16:04:35 +0000 (-0500) Subject: types: accept defineComponent return types in app.mount X-Git-Tag: v3.0.0-alpha.1~16 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7df5e70c83378ba23d4359693a7a6a72a4e1d18c;p=thirdparty%2Fvuejs%2Fcore.git types: accept defineComponent return types in app.mount --- diff --git a/packages/runtime-core/src/apiCreateApp.ts b/packages/runtime-core/src/apiCreateApp.ts index ce0a237155..fa50f0e8e3 100644 --- a/packages/runtime-core/src/apiCreateApp.ts +++ b/packages/runtime-core/src/apiCreateApp.ts @@ -17,7 +17,10 @@ export interface App { directive(name: string): Directive | undefined directive(name: string, directive: Directive): this mount( - rootComponent: Component, + rootComponent: + | Component + // for compatibility with defineComponent() return types + | { new (): ComponentPublicInstance }, rootContainer: HostElement | string, rootProps?: Data ): ComponentPublicInstance diff --git a/test-dts/defineComponent.test-d.tsx b/test-dts/defineComponent.test-d.tsx index 4024f7526d..5ae79cfefc 100644 --- a/test-dts/defineComponent.test-d.tsx +++ b/test-dts/defineComponent.test-d.tsx @@ -1,5 +1,5 @@ import { expectError, expectType } from 'tsd' -import { describe, defineComponent, PropType, ref } from './index' +import { describe, defineComponent, PropType, ref, createApp } from './index' describe('with object props', () => { interface ExpectedProps { @@ -240,3 +240,22 @@ describe('type inference w/ options API', () => { } }) }) + +describe('compatibility w/ createApp', () => { + const comp = defineComponent({}) + createApp().mount(comp, '#hello') + + const comp2 = defineComponent({ + props: { foo: String } + }) + createApp().mount(comp2, '#hello') + + const comp3 = defineComponent({ + setup() { + return { + a: 1 + } + } + }) + createApp().mount(comp3, '#hello') +})