-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
/
Copy pathoptions.d.ts
153 lines (142 loc) · 4.1 KB
/
options.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
import { Vue, CreateElement, CombinedVueInstance } from './vue'
import { VNode, VNodeData, VNodeDirective, NormalizedScopedSlot } from './vnode'
import { SetupContext } from './v3-setup-context'
import { DebuggerEvent } from './v3-generated'
import { DefineComponent } from './v3-define-component'
import { ComponentOptionsMixin } from './v3-component-options'
import { ObjectDirective, FunctionDirective } from './v3-directive'
type Constructor = {
new (...args: any[]): any
}
// we don't support infer props in async component
// N.B. ComponentOptions<V> is contravariant, the default generic should be bottom type
export type Component<
Data = DefaultData<never>,
Methods = DefaultMethods<never>,
Computed = DefaultComputed,
Props = DefaultProps,
SetupBindings = {}
> =
| typeof Vue
| FunctionalComponentOptions<Props>
| ComponentOptions<never, Data, Methods, Computed, Props, SetupBindings>
| DefineComponent<any, any, any, any, any, any, any, any, any, any, any>
type EsModule<T> = T | { default: T }
type ImportedComponent<
Data = DefaultData<never>,
Methods = DefaultMethods<never>,
Computed = DefaultComputed,
Props = DefaultProps,
SetupBindings = {}
> = EsModule<Component<Data, Methods, Computed, Props, SetupBindings>>
export type AsyncComponent<
Data = DefaultData<never>,
Methods = DefaultMethods<never>,
Computed = DefaultComputed,
Props = DefaultProps,
SetupBindings = {}
> =
| AsyncComponentPromise<Data, Methods, Computed, Props, SetupBindings>
| AsyncComponentFactory<Data, Methods, Computed, Props, SetupBindings>
export type AsyncComponentPromise<
Data = DefaultData<never>,
Methods = DefaultMethods<never>,
Computed = DefaultComputed,
Props = DefaultProps,
SetupBindings = {}
> = (
resolve: (
component: Component<Data, Methods, Computed, Props, SetupBindings>
) => void,
reject: (reason?: any) => void
) => Promise<
ImportedComponent<Data, Methods, Computed, Props, SetupBindings>
> | void
// Here is where the change for your issue is already correctly implemented
export type AsyncComponentFactory<
Data = DefaultData<never>,
Methods = DefaultMethods<never>,
Computed = DefaultComputed,
Props = DefaultProps,
SetupBindings = {}
> = () => {
component: Promise<
ImportedComponent<Data, Methods, Computed, Props, SetupBindings>
>
loading?: ImportedComponent
error?: ImportedComponent
delay?: number
timeout?: number
}
/**
* When the `Computed` type parameter on `ComponentOptions` is inferred,
* it should have a property with the return type of every get-accessor.
* Since there isn't a way to query for the return type of a function, we allow TypeScript
* to infer from the shape of `Accessors<Computed>` and work backwards.
*/
export type Accessors<T> = {
[K in keyof T]: (() => T[K]) | ComputedOptions<T[K]>
}
type DataDef<Data, Props, V> = Data | ((this: Readonly<Props> & V) => Data)
/**
* This type should be used when an array of strings is used for a component's `props` value.
*/
export type ThisTypedComponentOptionsWithArrayProps<
V extends Vue,
Data,
Methods,
Computed,
PropNames extends string,
SetupBindings,
Mixin extends ComponentOptionsMixin,
Extends extends ComponentOptionsMixin
> = object &
ComponentOptions<
V,
DataDef<Data, Record<PropNames, any>, V>,
Methods,
Computed,
PropNames[],
Record<PropNames, any>,
SetupBindings,
Mixin,
Extends
> &
ThisType<
CombinedVueInstance<
V,
Data,
Methods,
Computed,
Readonly<Record<PropNames, any>>,
SetupBindings,
Mixin,
Extends
>
>
/**
* This type should be used when an object mapped to `PropOptions` is used for a component's `props` value.
*/
export type ThisTypedComponentOptionsWithRecordProps<
V extends Vue,
Data,
Methods,
Computed,
Props,
SetupBindings,
Mixin extends ComponentOptionsMixin,
Extends extends ComponentOptionsMixin
> = object &
ComponentOptions<
V,
DataDef<Data, Props, V>,
Methods,
Computed,
RecordPropsDefinition<Props>,
Props,
SetupBindings,
Mixin,
Extends
> &
ThisType<
CombinedVueInstance<