@@ -9,10 +9,11 @@ import {
9
9
Plugin ,
10
10
Directive ,
11
11
Component ,
12
- reactive
12
+ reactive ,
13
+ ComponentPublicInstance
13
14
} from 'vue'
14
15
15
- import { createWrapper } from './vue-wrapper'
16
+ import { createWrapper , VueWrapper } from './vue-wrapper'
16
17
import { createEmitMixin } from './emitMixin'
17
18
import { createDataMixin } from './dataMixin'
18
19
import { MOUNT_ELEMENT_ID } from './constants'
@@ -40,7 +41,14 @@ interface MountingOptions {
40
41
stubs ?: Record < string , any >
41
42
}
42
43
43
- export function mount ( originalComponent : any , options ?: MountingOptions ) {
44
+ export function mount < T extends any > (
45
+ originalComponent : any ,
46
+ options ?: MountingOptions
47
+ ) : VueWrapper < any >
48
+ export function mount < T extends ComponentPublicInstance > (
49
+ originalComponent : new ( ) => T ,
50
+ options ?: MountingOptions
51
+ ) : VueWrapper < T > {
44
52
const component = { ...originalComponent }
45
53
46
54
// Reset the document.body
@@ -66,7 +74,10 @@ export function mount(originalComponent: any, options?: MountingOptions) {
66
74
// override component data with mounting options data
67
75
if ( options ?. data ) {
68
76
const dataMixin = createDataMixin ( options . data ( ) )
69
- component . mixins = [ ...( component . mixins || [ ] ) , dataMixin ]
77
+ ; ( component as any ) . mixins = [
78
+ ...( ( component as any ) . mixins || [ ] ) ,
79
+ dataMixin
80
+ ]
70
81
}
71
82
72
83
// we define props as reactive so that way when we update them with `setProps`
@@ -147,5 +158,5 @@ export function mount(originalComponent: any, options?: MountingOptions) {
147
158
// mount the app!
148
159
const app = vm . mount ( el )
149
160
150
- return createWrapper ( app , events , setProps )
161
+ return createWrapper < T > ( app , events , setProps )
151
162
}
0 commit comments