-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
/
v3-component-public-instance.d.ts
234 lines (215 loc) · 5.43 KB
/
v3-component-public-instance.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import {
DebuggerEvent,
ShallowUnwrapRef,
UnwrapNestedRefs
} from './v3-generated'
import { UnionToIntersection } from './common'
import { Vue, VueConstructor } from './vue'
import {
ComputedOptions,
MethodOptions,
ExtractComputedReturns,
ComponentOptionsMixin,
ComponentOptionsBase
} from './v3-component-options'
import { EmitFn, EmitsOptions } from './v3-setup-context'
/**
* Custom properties added to component instances in any way and can be accessed through `this`
*
* @example
* ```ts
* import { Router } from 'vue-router'
*
* declare module 'vue' {
* interface ComponentCustomProperties {
* $router: Router
* }
* }
* ```
*/
export interface ComponentCustomProperties {}
export type ComponentInstance = InstanceType<VueConstructor>
export type OptionTypesKeys = 'P' | 'B' | 'D' | 'C' | 'M' | 'Defaults'
export type OptionTypesType<
P = {},
B = {},
D = {},
C extends ComputedOptions = {},
M extends MethodOptions = {},
Defaults = {}
> = {
P: P
B: B
D: D
C: C
M: M
Defaults: Defaults
}
type IsDefaultMixinComponent<T> = T extends ComponentOptionsMixin
? ComponentOptionsMixin extends T
? true
: false
: false
type MixinToOptionTypes<T> = T extends ComponentOptionsBase<
infer P,
infer B,
infer D,
infer C,
infer M,
infer Mixin,
infer Extends,
any,
any,
infer Defaults
>
? OptionTypesType<P & {}, B & {}, D & {}, C & {}, M & {}, Defaults & {}> &
IntersectionMixin<Mixin> &
IntersectionMixin<Extends>
: never
// ExtractMixin(map type) is used to resolve circularly references
type ExtractMixin<T> = {
Mixin: MixinToOptionTypes<T>
}[T extends ComponentOptionsMixin ? 'Mixin' : never]
type IntersectionMixin<T> = IsDefaultMixinComponent<T> extends true
? OptionTypesType<{}, {}, {}, {}, {}, {}>
: UnionToIntersection<ExtractMixin<T>>
type UnwrapMixinsType<
T,
Type extends OptionTypesKeys
> = T extends OptionTypesType ? T[Type] : never
type EnsureNonVoid<T> = T extends void ? {} : T
export type CreateComponentPublicInstance<
P = {},
B = {},
D = {},
C extends ComputedOptions = {},
M extends MethodOptions = {},
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
E extends EmitsOptions = {},
PublicProps = P,
Defaults = {},
MakeDefaultsOptional extends boolean = false,
PublicMixin = IntersectionMixin<Mixin> & IntersectionMixin<Extends>,
PublicP = UnwrapMixinsType<PublicMixin, 'P'> & EnsureNonVoid<P>,
PublicB = UnwrapMixinsType<PublicMixin, 'B'> & EnsureNonVoid<B>,
PublicD = UnwrapMixinsType<PublicMixin, 'D'> & EnsureNonVoid<D>,
PublicC extends ComputedOptions = UnwrapMixinsType<PublicMixin, 'C'> &
EnsureNonVoid<C>,
PublicM extends MethodOptions = UnwrapMixinsType<PublicMixin, 'M'> &
EnsureNonVoid<M>,
PublicDefaults = UnwrapMixinsType<PublicMixin, 'Defaults'> &
EnsureNonVoid<Defaults>
> = ComponentPublicInstance<
PublicP,
PublicB,
PublicD,
PublicC,
PublicM,
E,
PublicProps,
PublicDefaults,
MakeDefaultsOptional
>
// public properties exposed on the proxy, which is used as the render context
// in templates (as `this` in the render option)
export type ComponentPublicInstance<
P = {}, // props type extracted from props option
B = {}, // raw bindings returned from setup()
D = {}, // return from data()
C extends ComputedOptions = {},
M extends MethodOptions = {},
E extends EmitsOptions = {},
PublicProps = P,
Defaults = {},
MakeDefaultsOptional extends boolean = false,
Options = ComponentOptionsBase<
any,
any,
any,
any,
any,
any,
any,
any,
any,
any
>
> = Vue3Instance<
D,
P,
PublicProps,
E,
Defaults,
MakeDefaultsOptional,
Options
> &
Readonly<P> &
ShallowUnwrapRef<B> &
UnwrapNestedRefs<D> &
ExtractComputedReturns<C> &
M &
ComponentCustomProperties
interface Vue3Instance<
D,
P,
PublicProps,
E,
Defaults,
MakeDefaultsOptional,
Options
> extends Vue<
D,
Readonly<
MakeDefaultsOptional extends true
? Partial<Defaults> & Omit<P & PublicProps, keyof Defaults>
: P & PublicProps
>,
ComponentPublicInstance | null,
ComponentPublicInstance,
ComponentPublicInstance[],
Options & MergedComponentOptionsOverride,
EmitFn<E>
> {}
type MergedHook<T = () => void> = T | T[]
export type MergedComponentOptionsOverride = {
beforeCreate?: MergedHook
created?: MergedHook
beforeMount?: MergedHook
mounted?: MergedHook
beforeUpdate?: MergedHook
updated?: MergedHook
activated?: MergedHook
deactivated?: MergedHook
/** @deprecated use `beforeUnmount` instead */
beforeDestroy?: MergedHook
beforeUnmount?: MergedHook
/** @deprecated use `unmounted` instead */
destroyed?: MergedHook
unmounted?: MergedHook
renderTracked?: MergedHook<DebuggerHook>
renderTriggered?: MergedHook<DebuggerHook>
errorCaptured?: MergedHook<ErrorCapturedHook>
}
export type DebuggerHook = (e: DebuggerEvent) => void
export type ErrorCapturedHook<TError = unknown> = (
err: TError,
instance: ComponentPublicInstance | null,
info: string
) => boolean | void
export type ComponentPublicInstanceConstructor<
T extends ComponentPublicInstance<
Props,
RawBindings,
D,
C,
M
> = ComponentPublicInstance<any, any, any>,
Props = any,
RawBindings = any,
D = any,
C extends ComputedOptions = ComputedOptions,
M extends MethodOptions = MethodOptions
> = {
new (...args: any[]): T
}