vue.d.ts 8.0 KB

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