@@ -12,12 +12,14 @@ import {
12
12
ComponentOptionsWithArrayProps ,
13
13
ComponentOptionsWithoutProps ,
14
14
ExtractPropTypes ,
15
- Component
15
+ Component ,
16
+ AppConfig ,
17
+ VNodeProps
16
18
} from 'vue'
17
19
18
20
import { config } from './config'
19
21
import { GlobalMountOptions } from './types'
20
- import { mergeGlobalProperties , isString } from './utils'
22
+ import { mergeGlobalProperties } from './utils'
21
23
import { processSlot } from './utils/compileSlots'
22
24
import { createWrapper , VueWrapper } from './vue-wrapper'
23
25
import { attachEmitListener } from './emitMixin'
@@ -28,7 +30,6 @@ import {
28
30
MOUNT_PARENT_NAME
29
31
} from './constants'
30
32
import { stubComponents } from './stubs'
31
- import { parse } from '@vue/compiler-dom'
32
33
33
34
type Slot = VNode | string | { render : Function } | Function
34
35
@@ -89,17 +90,17 @@ export function mount(
89
90
// normalise the incoming component
90
91
const component =
91
92
typeof originalComponent === 'function'
92
- ? {
93
+ ? defineComponent ( {
93
94
setup : ( _ , { attrs, slots } ) => ( ) =>
94
95
h ( originalComponent , attrs , slots )
95
- }
96
+ } )
96
97
: { ...originalComponent }
97
98
98
99
const el = document . createElement ( 'div' )
99
100
el . id = MOUNT_ELEMENT_ID
100
101
101
102
if ( options ?. attachTo ) {
102
- let to : Element
103
+ let to : Element | null
103
104
if ( typeof options . attachTo === 'string' ) {
104
105
to = document . querySelector ( options . attachTo )
105
106
if ( ! to ) {
@@ -117,29 +118,37 @@ export function mount(
117
118
// handle any slots passed via mounting options
118
119
const slots : VNodeNormalizedChildren =
119
120
options ?. slots &&
120
- Object . entries ( options . slots ) . reduce ( ( acc , [ name , slot ] ) => {
121
- // case of an SFC getting passed
122
- if ( typeof slot === 'object' && 'render' in slot ) {
123
- acc [ name ] = slot . render
124
- return acc
125
- }
121
+ Object . entries ( options . slots ) . reduce (
122
+ (
123
+ acc : { [ key : string ] : Function } ,
124
+ [ name , slot ] : [ string , Slot ]
125
+ ) : { [ key : string ] : Function } => {
126
+ // case of an SFC getting passed
127
+ if ( typeof slot === 'object' && 'render' in slot ) {
128
+ acc [ name ] = slot . render
129
+ return acc
130
+ }
126
131
127
- if ( typeof slot === 'function' ) {
128
- acc [ name ] = slot
129
- return acc
130
- }
132
+ if ( typeof slot === 'function' ) {
133
+ acc [ name ] = slot
134
+ return acc
135
+ }
131
136
132
- if ( typeof slot === 'object' ) {
133
- acc [ name ] = ( ) => slot
134
- return acc
135
- }
137
+ if ( typeof slot === 'object' ) {
138
+ acc [ name ] = ( ) => slot
139
+ return acc
140
+ }
141
+
142
+ if ( typeof slot === 'string' ) {
143
+ // slot is most probably a scoped slot string or a plain string
144
+ acc [ name ] = ( props : VNodeProps ) => h ( processSlot ( slot ) , props )
145
+ return acc
146
+ }
136
147
137
- if ( typeof slot === 'string' ) {
138
- // slot is most probably a scoped slot string or a plain string
139
- acc [ name ] = ( props ) => h ( processSlot ( slot ) , props )
140
148
return acc
141
- }
142
- } , { } )
149
+ } ,
150
+ { }
151
+ )
143
152
144
153
// override component data with mounting options data
145
154
if ( options ?. data ) {
@@ -184,8 +193,10 @@ export function mount(
184
193
if ( global ?. mocks ) {
185
194
const mixin = {
186
195
beforeCreate ( ) {
187
- for ( const [ k , v ] of Object . entries ( global . mocks ) ) {
188
- this [ k ] = v
196
+ for ( const [ k , v ] of Object . entries (
197
+ global . mocks as { [ key : string ] : any }
198
+ ) ) {
199
+ ; ( this as any ) [ k ] = v
189
200
}
190
201
}
191
202
}
@@ -195,7 +206,10 @@ export function mount(
195
206
196
207
// AppConfig
197
208
if ( global . config ) {
198
- for ( const [ k , v ] of Object . entries ( global . config ) ) {
209
+ for ( const [ k , v ] of Object . entries ( global . config ) as [
210
+ keyof Omit < AppConfig , 'isNativeTag' > ,
211
+ any
212
+ ] [ ] ) {
199
213
app . config [ k ] = v
200
214
}
201
215
}
0 commit comments