vue.d.ts 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. import {
  2. Component,
  3. AsyncComponent,
  4. ComponentOptions,
  5. FunctionalComponentOptions,
  6. DirectiveOptions,
  7. DirectiveFunction,
  8. RecordPropsDefinition,
  9. ThisTypedComponentOptionsWithArrayProps,
  10. ThisTypedComponentOptionsWithRecordProps,
  11. WatchOptions
  12. } from './options'
  13. import { VNode, VNodeData, VNodeChildren, NormalizedScopedSlot } from './vnode'
  14. import { PluginFunction, PluginObject } from './plugin'
  15. import { DefineComponent } from './v3-define-component'
  16. import { nextTick } from './v3-generated'
  17. export interface CreateElement {
  18. (
  19. tag?:
  20. | string
  21. | Component<any, any, any, any>
  22. | AsyncComponent<any, any, any, any>
  23. | (() => Component),
  24. children?: VNodeChildren
  25. ): VNode
  26. (
  27. tag?:
  28. | string
  29. | Component<any, any, any, any>
  30. | AsyncComponent<any, any, any, any>
  31. | (() => Component),
  32. data?: VNodeData,
  33. children?: VNodeChildren
  34. ): VNode
  35. }
  36. type NeverFallback<T, D> = [T] extends [never] ? D : T
  37. export interface Vue<
  38. Data = Record<string, any>,
  39. Props = Record<string, any>,
  40. Instance = never,
  41. Options = never,
  42. Emit = (event: string, ...args: any[]) => Vue
  43. > {
  44. // properties with different types in defineComponent()
  45. readonly $data: Data
  46. readonly $props: Props
  47. readonly $parent: NeverFallback<Instance, Vue> | null
  48. readonly $root: NeverFallback<Instance, Vue>
  49. readonly $children: NeverFallback<Instance, Vue>[]
  50. readonly $options: NeverFallback<Options, ComponentOptions<Vue>>
  51. $emit: Emit
  52. // Vue 2 only or shared
  53. readonly $el: Element
  54. readonly $refs: {
  55. [key: string]:
  56. | NeverFallback<Instance, Vue>
  57. | Vue
  58. | Element
  59. | (NeverFallback<Instance, Vue> | Vue | Element)[]
  60. | undefined
  61. }
  62. readonly $slots: { [key: string]: VNode[] | undefined }
  63. readonly $scopedSlots: { [key: string]: NormalizedScopedSlot | undefined }
  64. readonly $isServer: boolean
  65. readonly $ssrContext: any
  66. readonly $vnode: VNode
  67. readonly $attrs: Record<string, string>
  68. readonly $listeners: Record<string, Function | Function[]>
  69. $mount(elementOrSelector?: Element | string, hydrating?: boolean): this
  70. $forceUpdate(): void
  71. $destroy(): void
  72. $set: typeof Vue.set
  73. $delete: typeof Vue.delete
  74. $watch(
  75. expOrFn: string,
  76. callback: (this: this, n: any, o: any) => void,
  77. options?: WatchOptions
  78. ): () => void
  79. $watch<T>(
  80. expOrFn: (this: this) => T,
  81. callback: (this: this, n: T, o: T) => void,
  82. options?: WatchOptions
  83. ): () => void
  84. $on(event: string | string[], callback: Function): this
  85. $once(event: string | string[], callback: Function): this
  86. $off(event?: string | string[], callback?: Function): this
  87. $nextTick: typeof nextTick
  88. $createElement: CreateElement
  89. }
  90. export type CombinedVueInstance<
  91. Instance extends Vue,
  92. Data,
  93. Methods,
  94. Computed,
  95. Props,
  96. SetupBindings
  97. > = Data &
  98. Methods &
  99. Computed &
  100. Props &
  101. Instance &
  102. (SetupBindings extends void ? {} : SetupBindings)
  103. export type ExtendedVue<
  104. Instance extends Vue,
  105. Data,
  106. Methods,
  107. Computed,
  108. Props,
  109. SetupBindings
  110. > = VueConstructor<
  111. CombinedVueInstance<Instance, Data, Methods, Computed, Props, SetupBindings> &
  112. Vue
  113. >
  114. export interface VueConfiguration {
  115. silent: boolean
  116. optionMergeStrategies: any
  117. devtools: boolean
  118. productionTip: boolean
  119. performance: boolean
  120. errorHandler(err: Error, vm: Vue, info: string): void
  121. warnHandler(msg: string, vm: Vue, trace: string): void
  122. ignoredElements: (string | RegExp)[]
  123. keyCodes: { [key: string]: number | number[] }
  124. async: boolean
  125. }
  126. export interface VueConstructor<V extends Vue = Vue> {
  127. /**
  128. * new with array props
  129. */
  130. new <
  131. Data = object,
  132. Methods = object,
  133. Computed = object,
  134. PropNames extends string = never,
  135. SetupBindings = {}
  136. >(
  137. options?: ThisTypedComponentOptionsWithArrayProps<
  138. V,
  139. Data,
  140. Methods,
  141. Computed,
  142. PropNames,
  143. SetupBindings
  144. >
  145. ): CombinedVueInstance<
  146. V,
  147. Data,
  148. Methods,
  149. Computed,
  150. Record<PropNames, any>,
  151. SetupBindings
  152. >
  153. /**
  154. * new with object props
  155. * ideally, the return type should just contain Props,
  156. * not Record<keyof Props, any>. But TS requires to have Base constructors
  157. * with the same return type.
  158. */
  159. new <
  160. Data = object,
  161. Methods = object,
  162. Computed = object,
  163. Props = object,
  164. SetupBindings = {}
  165. >(
  166. options?: ThisTypedComponentOptionsWithRecordProps<
  167. V,
  168. Data,
  169. Methods,
  170. Computed,
  171. Props,
  172. SetupBindings
  173. >
  174. ): CombinedVueInstance<
  175. V,
  176. Data,
  177. Methods,
  178. Computed,
  179. Record<keyof Props, any>,
  180. SetupBindings
  181. >
  182. /**
  183. * new with no props
  184. */
  185. new (options?: ComponentOptions<V>): CombinedVueInstance<
  186. V,
  187. object,
  188. object,
  189. object,
  190. Record<keyof object, any>,
  191. {}
  192. >
  193. /**
  194. * extend with array props
  195. */
  196. extend<
  197. Data,
  198. Methods,
  199. Computed,
  200. PropNames extends string = never,
  201. SetupBindings = {}
  202. >(
  203. options?: ThisTypedComponentOptionsWithArrayProps<
  204. V,
  205. Data,
  206. Methods,
  207. Computed,
  208. PropNames,
  209. SetupBindings
  210. >
  211. ): ExtendedVue<
  212. V,
  213. Data,
  214. Methods,
  215. Computed,
  216. Record<PropNames, any>,
  217. SetupBindings
  218. >
  219. /**
  220. * extend with object props
  221. */
  222. extend<Data, Methods, Computed, Props, SetupBindings = {}>(
  223. options?: ThisTypedComponentOptionsWithRecordProps<
  224. V,
  225. Data,
  226. Methods,
  227. Computed,
  228. Props,
  229. SetupBindings
  230. >
  231. ): ExtendedVue<V, Data, Methods, Computed, Props, SetupBindings>
  232. /**
  233. * extend with functional + array props
  234. */
  235. extend<PropNames extends string = never>(
  236. definition: FunctionalComponentOptions<Record<PropNames, any>, PropNames[]>
  237. ): ExtendedVue<V, {}, {}, {}, Record<PropNames, any>, {}>
  238. /**
  239. * extend with functional + object props
  240. */
  241. extend<Props>(
  242. definition: FunctionalComponentOptions<Props, RecordPropsDefinition<Props>>
  243. ): ExtendedVue<V, {}, {}, {}, Props, {}>
  244. /**
  245. * extend with no props
  246. */
  247. extend(options?: ComponentOptions<V>): ExtendedVue<V, {}, {}, {}, {}, {}>
  248. nextTick<T>(callback: (this: T) => void, context?: T): void
  249. nextTick(): Promise<void>
  250. set<T>(object: object, key: string | number, value: T): T
  251. set<T>(array: T[], key: number, value: T): T
  252. delete(object: object, key: string | number): void
  253. delete<T>(array: T[], key: number): void
  254. directive(
  255. id: string,
  256. definition?: DirectiveOptions | DirectiveFunction
  257. ): DirectiveOptions
  258. filter(id: string, definition?: Function): Function
  259. component(id: string): VueConstructor
  260. component<VC extends VueConstructor>(id: string, constructor: VC): VC
  261. component<Data, Methods, Computed, Props, SetupBindings>(
  262. id: string,
  263. definition: AsyncComponent<Data, Methods, Computed, Props>
  264. ): ExtendedVue<V, Data, Methods, Computed, Props, SetupBindings>
  265. component<
  266. Data,
  267. Methods,
  268. Computed,
  269. PropNames extends string = never,
  270. SetupBindings = {}
  271. >(
  272. id: string,
  273. definition?: ThisTypedComponentOptionsWithArrayProps<
  274. V,
  275. Data,
  276. Methods,
  277. Computed,
  278. PropNames,
  279. SetupBindings
  280. >
  281. ): ExtendedVue<
  282. V,
  283. Data,
  284. Methods,
  285. Computed,
  286. Record<PropNames, any>,
  287. SetupBindings
  288. >
  289. component<Data, Methods, Computed, Props, SetupBindings>(
  290. id: string,
  291. definition?: ThisTypedComponentOptionsWithRecordProps<
  292. V,
  293. Data,
  294. Methods,
  295. Computed,
  296. Props,
  297. SetupBindings
  298. >
  299. ): ExtendedVue<V, Data, Methods, Computed, Props, SetupBindings>
  300. component<PropNames extends string>(
  301. id: string,
  302. definition: FunctionalComponentOptions<Record<PropNames, any>, PropNames[]>
  303. ): ExtendedVue<V, {}, {}, {}, Record<PropNames, any>, {}>
  304. component<Props>(
  305. id: string,
  306. definition: FunctionalComponentOptions<Props, RecordPropsDefinition<Props>>
  307. ): ExtendedVue<V, {}, {}, {}, Props, {}>
  308. component(
  309. id: string,
  310. definition?: ComponentOptions<V>
  311. ): ExtendedVue<V, {}, {}, {}, {}, {}>
  312. component<T extends DefineComponent<any, any, any, any, any, any, any, any>>(
  313. id: string,
  314. definition?: T
  315. ): T
  316. use<T>(
  317. plugin: PluginObject<T> | PluginFunction<T>,
  318. options?: T
  319. ): VueConstructor<V>
  320. use(
  321. plugin: PluginObject<any> | PluginFunction<any>,
  322. ...options: any[]
  323. ): VueConstructor<V>
  324. mixin(mixin: VueConstructor | ComponentOptions<Vue>): VueConstructor<V>
  325. compile(template: string): {
  326. render(createElement: typeof Vue.prototype.$createElement): VNode
  327. staticRenderFns: (() => VNode)[]
  328. }
  329. observable<T>(obj: T): T
  330. util: {
  331. warn(msg: string, vm?: InstanceType<VueConstructor>): void
  332. }
  333. config: VueConfiguration
  334. version: string
  335. }
  336. export const Vue: VueConstructor