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