vue.d.ts 8.2 KB

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