1
- import { ComponentOptions , SetupContext , UnwrapRef , ComponentObjectPropsOptions , ExtractPropTypes } from 'vue'
2
- import { Vue , VueBase , VueMixin } from './vue'
1
+ import { ComponentOptions , UnwrapRef , ComponentObjectPropsOptions , ExtractPropTypes } from 'vue'
2
+ import { EmitsOptions , ObjectEmitsOptions , Vue , VueConstructor , VueMixin } from './vue'
3
3
4
4
export function Options < V extends Vue > (
5
5
options : ComponentOptions & ThisType < V >
6
- ) : < VC extends VueBase > ( target : VC ) => VC {
6
+ ) : < VC extends VueConstructor > ( target : VC ) => VC {
7
7
return ( Component ) => {
8
8
Component . __vccBase = options
9
9
return Component
@@ -12,7 +12,7 @@ export function Options<V extends Vue>(
12
12
13
13
export interface VueDecorator {
14
14
// Class decorator
15
- ( Ctor : VueBase ) : void
15
+ ( Ctor : VueConstructor ) : void
16
16
17
17
// Property decorator
18
18
( target : Vue , key : string ) : void
@@ -24,9 +24,9 @@ export interface VueDecorator {
24
24
export function createDecorator (
25
25
factory : ( options : ComponentOptions , key : string , index : number ) => void
26
26
) : VueDecorator {
27
- return ( target : Vue | VueBase , key ?: any , index ?: any ) => {
27
+ return ( target : Vue | VueConstructor , key ?: any , index ?: any ) => {
28
28
const Ctor =
29
- typeof target === 'function' ? target : ( target . constructor as VueBase )
29
+ typeof target === 'function' ? target : ( target . constructor as VueConstructor )
30
30
if ( ! Ctor . __vccDecorators ) {
31
31
Ctor . __vccDecorators = [ ]
32
32
}
@@ -52,40 +52,51 @@ export type UnionToIntersection<U> = (
52
52
export type ExtractInstance < T > = T extends VueMixin < infer V > ? V : never
53
53
54
54
export type MixedVueBase < Mixins extends VueMixin [ ] > = Mixins extends ( infer T ) [ ]
55
- ? VueBase < UnionToIntersection < ExtractInstance < T > > & Vue > & PropsMixin
55
+ ? VueConstructor < UnionToIntersection < ExtractInstance < T > > & Vue > & PropsMixin
56
56
: never
57
57
58
58
export function mixins < T extends VueMixin [ ] > ( ...Ctors : T ) : MixedVueBase < T >
59
- export function mixins ( ...Ctors : VueMixin [ ] ) : VueBase {
60
- return class MixedVue < Props > extends Vue < Props > {
59
+ export function mixins ( ...Ctors : VueMixin [ ] ) : VueConstructor {
60
+ return class MixedVue extends Vue {
61
61
static __vccExtend ( options : ComponentOptions ) {
62
62
Ctors . forEach ( ( Ctor ) => Ctor . __vccExtend ( options ) )
63
63
}
64
64
65
- constructor ( props : Props , ctx : SetupContext ) {
66
- super ( props , ctx )
65
+ constructor ( ... args : any [ ] ) {
66
+ super ( ... args )
67
67
68
68
Ctors . forEach ( ( Ctor ) => {
69
- const data = new ( Ctor as any ) ( props , ctx )
69
+ const data = new ( Ctor as VueConstructor ) ( ... args )
70
70
Object . keys ( data ) . forEach ( ( key ) => {
71
- ; ( this as any ) [ key ] = data [ key ]
71
+ ; ( this as any ) [ key ] = ( data as any ) [ key ]
72
72
} )
73
73
} )
74
74
}
75
75
}
76
76
}
77
77
78
- export function props < PropNames extends string , Props = Readonly < { [ key in PropNames ] ?: any } > > ( propNames : PropNames [ ] ) : VueBase < Vue < Props > & Props >
79
- export function props < PropsOptions extends ComponentObjectPropsOptions , Props = Readonly < ExtractPropTypes < PropsOptions > > > ( propsOptions : PropsOptions ) : VueBase < Vue < Props > & Props >
80
- export function props ( propsOptions : string [ ] | ComponentObjectPropsOptions ) : VueBase {
81
- class PropsMixin < Props > extends Vue < Props > {
78
+ export function props < PropNames extends string , Props = Readonly < { [ key in PropNames ] ?: any } > > ( propNames : PropNames [ ] ) : VueConstructor < Vue < Props > & Props >
79
+ export function props < PropsOptions extends ComponentObjectPropsOptions , Props = Readonly < ExtractPropTypes < PropsOptions > > > ( propsOptions : PropsOptions ) : VueConstructor < Vue < Props > & Props >
80
+ export function props ( propsOptions : string [ ] | ComponentObjectPropsOptions ) : VueConstructor {
81
+ class PropsMixin extends Vue {
82
82
static __vccExtend ( options : ComponentOptions ) {
83
83
options . props = propsOptions
84
84
}
85
85
}
86
86
return PropsMixin
87
87
}
88
88
89
+ export function emits < EmitNames extends string > ( emitNames : EmitNames [ ] ) : VueConstructor < Vue < unknown , EmitNames [ ] > >
90
+ export function emits < EmitsOptions extends ObjectEmitsOptions > ( emitsOptions : EmitsOptions ) : VueConstructor < Vue < unknown , EmitsOptions > >
91
+ export function emits ( emitsOptions : EmitsOptions ) : VueConstructor {
92
+ class EmitsMixin extends Vue {
93
+ static __vccExtend ( options : ComponentOptions ) {
94
+ options . emits = emitsOptions
95
+ }
96
+ }
97
+ return EmitsMixin
98
+ }
99
+
89
100
export function setup < R > ( setupFn : ( ) => R ) : UnwrapRef < R > {
90
101
// Hack to delay the invocation of setup function.
91
102
// Will be called after dealing with class properties.
0 commit comments