1- import { nextTick , App , ComponentPublicInstance , VNode } from 'vue'
1+ import {
2+ nextTick ,
3+ App ,
4+ ComponentPublicInstance ,
5+ VNode ,
6+ ExtractComponentEmits
7+ } from 'vue'
28
39import { config } from './config'
410import domEvents from './constants/dom-events'
@@ -72,9 +78,24 @@ function createVMProxy<T extends ComponentPublicInstance>(
7278 } )
7379}
7480
81+ type ResolveComponentEmitKeys < T > = keyof ResolveEmitRecord < T >
82+
83+ type ResolveEmitRecord < T > = ExtractComponentEmits < T > extends infer E
84+ ? [ E ] extends [ Array < infer EE extends string > ]
85+ ? Record < EE , any [ ] >
86+ : {
87+ [ K in keyof E ] : ( E [ K ] extends ( ...args : infer Args ) => any
88+ ? Args extends { length : 0 }
89+ ? void
90+ : Args extends { length : 1 }
91+ ? Args [ 0 ]
92+ : Args
93+ : void ) [ ]
94+ }
95+ : never
96+
7597export class VueWrapper <
76- VM = unknown ,
77- T extends ComponentPublicInstance = VM & ComponentPublicInstance
98+ T extends ComponentPublicInstance = ComponentPublicInstance
7899> extends BaseWrapper < Node > {
79100 private readonly componentVM : T
80101 private readonly rootVM : ComponentPublicInstance | undefined | null
@@ -226,11 +247,11 @@ export class VueWrapper<
226247 return selector ? props [ selector ] : props
227248 }
228249
229- emitted < T = unknown > ( ) : Record < string , T [ ] >
230- emitted < T = unknown [ ] > ( eventName : string ) : undefined | T [ ]
231- emitted < T = unknown > (
232- eventName ?: string
233- ) : undefined | T [ ] | Record < string , T [ ] > {
250+ emitted ( ) : ResolveEmitRecord < T >
251+ emitted < E extends ResolveComponentEmitKeys < T > > (
252+ eventName : E
253+ ) : undefined | ResolveEmitRecord < T > [ E ]
254+ emitted ( eventName ?: string ) {
234255 return emitted ( this . vm , eventName )
235256 }
236257
@@ -239,7 +260,7 @@ export class VueWrapper<
239260 return domWrapper . isVisible ( )
240261 }
241262
242- setData ( data : Record < string , unknown > ) : Promise < void > {
263+ setData ( data : Partial < T [ '$data' ] > ) : Promise < void > {
243264 mergeDeep ( this . componentVM . $data , data )
244265 return nextTick ( )
245266 }
@@ -253,7 +274,14 @@ export class VueWrapper<
253274 return nextTick ( )
254275 }
255276
256- setValue ( value : unknown , prop ?: string ) : Promise < void > {
277+ setValue <
278+ V extends T [ '$props' ] extends { modelValue ?: infer MV } ? MV : never
279+ > ( value : V ) : Promise < void >
280+ setValue < P extends keyof T [ '$props' ] > (
281+ value : T [ '$props' ] [ P ] ,
282+ prop : P
283+ ) : Promise < void >
284+ setValue ( value : unknown , prop ?: unknown ) : Promise < void > {
257285 const propEvent = prop || 'modelValue'
258286 this . vm . $emit ( `update:${ propEvent } ` , value )
259287 return this . vm . $nextTick ( )
0 commit comments