-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
vue.d.ts
211 lines (203 loc) · 5.85 KB
/
vue.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
/**
* Extends interfaces in Vue.js
*/
import type Vue from 'vue'
import type { MetaInfo } from 'vue-meta'
import type { Route } from 'vue-router'
import type { RecordPropsDefinition, ComponentOptions } from 'vue/types/options'
import type { ComponentOptionsMixin } from 'vue/types/v3-component-options'
import type { CombinedVueInstance } from 'vue/types/vue'
import type { NuxtRuntimeConfig } from '../config/runtime'
import type { Context, Middleware, Transition, NuxtApp } from './index'
// https://github.com/vuejs/vue/blob/dev/types/options.d.ts#L63-L66
type DefaultData<V> = object | ((this: V) => object)
type DefaultProps = Record<string, any>
type DefaultMethods<V> = { [key: string]: (this: V, ...args: any[]) => any }
type DefaultComputed = { [key: string]: any }
type DefaultAsyncData<V> = ((this: V, context: Context) => Promise<object | void> | object | void)
declare module 'vue/types/options' {
interface ComponentOptions<
V extends Vue,
/* eslint-disable no-unused-vars,@typescript-eslint/no-unused-vars */
Data = DefaultData<V>,
Methods = DefaultMethods<V>,
Computed = DefaultComputed,
PropsDef = PropsDefinition<DefaultProps>,
Props = DefaultProps,
RawBindings = {},
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
/* eslint-enable no-unused-vars,@typescript-eslint/no-unused-vars */
AsyncData = DefaultAsyncData<V>
> {
// eslint-disable-next-line @typescript-eslint/ban-types
asyncData?: AsyncData
fetch?(ctx: Context): Promise<void> | void
fetchKey?: string | ((getKey: (id: string) => number) => string)
fetchDelay?: number
fetchOnServer?: boolean | (() => boolean)
head?: MetaInfo | (() => MetaInfo)
key?: string | ((to: Route) => string)
layout?: string | ((ctx: Context) => string)
loading?: boolean
middleware?: Middleware | Middleware[]
scrollToTop?: boolean
transition?: string | Transition | ((to: Route, from: Route | undefined) => string | Transition)
validate?(ctx: Context): Promise<boolean> | boolean
watchQuery?: boolean | string[] | ((newQuery: Route['query'], oldQuery: Route['query']) => boolean)
meta?: { [key: string]: any }
}
}
type DataDef<Data, Props, V> = Data | ((this: Readonly<Props> & V) => Data)
type Awaited<T> = T extends PromiseLike<infer U> ? Awaited<U> : T
type Merged<Data, AsyncData> = {
[key in keyof Data | keyof AsyncData]: key extends keyof Data ? key extends keyof AsyncData ? NonNullable<Data[key]> | AsyncData[key] : Data[key] : key extends keyof AsyncData ? AsyncData[key] : never
}
type ThisTypedComponentOptionsWithArrayPropsAndAsyncData<
V extends Vue,
Data,
Methods,
Computed,
PropNames extends string,
SetupBindings,
Mixin extends ComponentOptionsMixin,
Extends extends ComponentOptionsMixin,
AsyncData extends DefaultAsyncData<V> = DefaultAsyncData<V>
> = object &
ComponentOptions<
V,
DataDef<Data, Record<PropNames, any>, V>,
Methods,
Computed,
PropNames[],
Record<PropNames, any>,
Merged<SetupBindings, Awaited<ReturnType<AsyncData>>>,
Mixin,
Extends,
AsyncData
> &
ThisType<
CombinedVueInstance<
V,
Merged<Data, Awaited<ReturnType<AsyncData>>>,
Methods,
Computed,
Readonly<Record<PropNames, any>>,
SetupBindings,
Mixin,
Extends
>
>
export type ThisTypedComponentOptionsWithRecordPropsAndAsyncData<
V extends Vue,
Data,
Methods,
Computed,
Props,
SetupBindings,
Mixin extends ComponentOptionsMixin,
Extends extends ComponentOptionsMixin,
AsyncData extends DefaultAsyncData<V>
> = object &
ComponentOptions<
V,
DataDef<Data, Props, V>,
Methods,
Computed,
RecordPropsDefinition<Props>,
Props,
Merged<SetupBindings, Awaited<ReturnType<AsyncData>>>,
Mixin,
Extends,
AsyncData
> &
ThisType<
CombinedVueInstance<
V,
Merged<Data, Awaited<ReturnType<AsyncData>>>,
Methods,
Computed,
Readonly<Props>,
SetupBindings,
Mixin,
Extends
>
>
declare module 'vue/types/vue' {
interface Vue {
$config: NuxtRuntimeConfig
$nuxt: NuxtApp
$fetch(): Promise<void> | void
$fetchState: {
error: Error | null
pending: boolean
timestamp: number
}
}
interface VueConstructor<V extends Vue> {
/** extend with array props */
extend<
Data,
Methods,
Computed,
PropNames extends string = never,
SetupBindings = {},
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
AsyncData extends DefaultAsyncData<V> = DefaultAsyncData<V>
>(
options?: ThisTypedComponentOptionsWithArrayPropsAndAsyncData<
V,
Data,
Methods,
Computed,
PropNames,
SetupBindings,
Mixin,
Extends,
AsyncData
>
): ExtendedVue<
V,
Data,
Methods,
Computed,
Record<PropNames, any>,
Merged<SetupBindings, Awaited<ReturnType<AsyncData>>>,
Mixin,
Extends
>
/** extend with object props */
extend<
Data,
Methods,
Computed,
Props,
SetupBindings = {},
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
AsyncData extends DefaultAsyncData<V> = DefaultAsyncData<V>
>(
options?: ThisTypedComponentOptionsWithRecordPropsAndAsyncData<
V,
Data,
Methods,
Computed,
Props,
SetupBindings,
Mixin,
Extends,
AsyncData
>
): ExtendedVue<
V,
Data,
Methods,
Computed,
Props,
Merged<SetupBindings, Awaited<ReturnType<AsyncData>>>,
Mixin,
Extends
>
}
}