vue.d.ts 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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 & Methods & Computed & Props & Instance & SetupBindings
  85. export type ExtendedVue<
  86. Instance extends Vue,
  87. Data,
  88. Methods,
  89. Computed,
  90. Props,
  91. SetupBindings
  92. > = VueConstructor<
  93. CombinedVueInstance<Instance, Data, Methods, Computed, Props, SetupBindings> &
  94. Vue
  95. >
  96. export interface VueConfiguration {
  97. silent: boolean
  98. optionMergeStrategies: any
  99. devtools: boolean
  100. productionTip: boolean
  101. performance: boolean
  102. errorHandler(err: Error, vm: Vue, info: string): void
  103. warnHandler(msg: string, vm: Vue, trace: string): void
  104. ignoredElements: (string | RegExp)[]
  105. keyCodes: { [key: string]: number | number[] }
  106. async: boolean
  107. }
  108. export interface VueConstructor<V extends Vue = Vue> {
  109. /**
  110. * new with array props
  111. */
  112. new <
  113. Data = object,
  114. Methods = object,
  115. Computed = object,
  116. PropNames extends string = never,
  117. SetupBindings = {}
  118. >(
  119. options?: ThisTypedComponentOptionsWithArrayProps<
  120. V,
  121. Data,
  122. Methods,
  123. Computed,
  124. PropNames,
  125. SetupBindings
  126. >
  127. ): CombinedVueInstance<
  128. V,
  129. Data,
  130. Methods,
  131. Computed,
  132. Record<PropNames, any>,
  133. SetupBindings
  134. >
  135. /**
  136. * new with object props
  137. * ideally, the return type should just contain Props,
  138. * not Record<keyof Props, any>. But TS requires to have Base constructors
  139. * with the same return type.
  140. */
  141. new <
  142. Data = object,
  143. Methods = object,
  144. Computed = object,
  145. Props = object,
  146. SetupBindings = {}
  147. >(
  148. options?: ThisTypedComponentOptionsWithRecordProps<
  149. V,
  150. Data,
  151. Methods,
  152. Computed,
  153. Props,
  154. SetupBindings
  155. >
  156. ): CombinedVueInstance<
  157. V,
  158. Data,
  159. Methods,
  160. Computed,
  161. Record<keyof Props, any>,
  162. SetupBindings
  163. >
  164. /**
  165. * new with no props
  166. */
  167. new (options?: ComponentOptions<V>): CombinedVueInstance<
  168. V,
  169. object,
  170. object,
  171. object,
  172. Record<keyof object, any>,
  173. {}
  174. >
  175. /**
  176. * extend with array props
  177. */
  178. extend<
  179. Data,
  180. Methods,
  181. Computed,
  182. PropNames extends string = never,
  183. SetupBindings = {}
  184. >(
  185. options?: ThisTypedComponentOptionsWithArrayProps<
  186. V,
  187. Data,
  188. Methods,
  189. Computed,
  190. PropNames,
  191. SetupBindings
  192. >
  193. ): ExtendedVue<
  194. V,
  195. Data,
  196. Methods,
  197. Computed,
  198. Record<PropNames, any>,
  199. SetupBindings
  200. >
  201. /**
  202. * extend with object props
  203. */
  204. extend<Data, Methods, Computed, Props, SetupBindings = {}>(
  205. options?: ThisTypedComponentOptionsWithRecordProps<
  206. V,
  207. Data,
  208. Methods,
  209. Computed,
  210. Props,
  211. SetupBindings
  212. >
  213. ): ExtendedVue<V, Data, Methods, Computed, Props, SetupBindings>
  214. /**
  215. * extend with functional + array props
  216. */
  217. extend<PropNames extends string = never>(
  218. definition: FunctionalComponentOptions<Record<PropNames, any>, PropNames[]>
  219. ): ExtendedVue<V, {}, {}, {}, Record<PropNames, any>, {}>
  220. /**
  221. * extend with functional + object props
  222. */
  223. extend<Props>(
  224. definition: FunctionalComponentOptions<Props, RecordPropsDefinition<Props>>
  225. ): ExtendedVue<V, {}, {}, {}, Props, {}>
  226. /**
  227. * extend with no props
  228. */
  229. extend(options?: ComponentOptions<V>): ExtendedVue<V, {}, {}, {}, {}, {}>
  230. nextTick<T>(callback: (this: T) => void, context?: T): void
  231. nextTick(): Promise<void>
  232. set<T>(object: object, key: string | number, value: T): T
  233. set<T>(array: T[], key: number, value: T): T
  234. delete(object: object, key: string | number): void
  235. delete<T>(array: T[], key: number): void
  236. directive(
  237. id: string,
  238. definition?: DirectiveOptions | DirectiveFunction
  239. ): DirectiveOptions
  240. filter(id: string, definition?: Function): Function
  241. component(id: string): VueConstructor
  242. component<VC extends VueConstructor>(id: string, constructor: VC): VC
  243. component<Data, Methods, Computed, Props, SetupBindings>(
  244. id: string,
  245. definition: AsyncComponent<Data, Methods, Computed, Props>
  246. ): ExtendedVue<V, Data, Methods, Computed, Props, SetupBindings>
  247. component<
  248. Data,
  249. Methods,
  250. Computed,
  251. PropNames extends string = never,
  252. SetupBindings = {}
  253. >(
  254. id: string,
  255. definition?: ThisTypedComponentOptionsWithArrayProps<
  256. V,
  257. Data,
  258. Methods,
  259. Computed,
  260. PropNames,
  261. SetupBindings
  262. >
  263. ): ExtendedVue<
  264. V,
  265. Data,
  266. Methods,
  267. Computed,
  268. Record<PropNames, any>,
  269. SetupBindings
  270. >
  271. component<Data, Methods, Computed, Props, SetupBindings>(
  272. id: string,
  273. definition?: ThisTypedComponentOptionsWithRecordProps<
  274. V,
  275. Data,
  276. Methods,
  277. Computed,
  278. Props,
  279. SetupBindings
  280. >
  281. ): ExtendedVue<V, Data, Methods, Computed, Props, SetupBindings>
  282. component<PropNames extends string>(
  283. id: string,
  284. definition: FunctionalComponentOptions<Record<PropNames, any>, PropNames[]>
  285. ): ExtendedVue<V, {}, {}, {}, Record<PropNames, any>, {}>
  286. component<Props>(
  287. id: string,
  288. definition: FunctionalComponentOptions<Props, RecordPropsDefinition<Props>>
  289. ): ExtendedVue<V, {}, {}, {}, Props, {}>
  290. component(
  291. id: string,
  292. definition?: ComponentOptions<V>
  293. ): ExtendedVue<V, {}, {}, {}, {}, {}>
  294. use<T>(
  295. plugin: PluginObject<T> | PluginFunction<T>,
  296. options?: T
  297. ): VueConstructor<V>
  298. use(
  299. plugin: PluginObject<any> | PluginFunction<any>,
  300. ...options: any[]
  301. ): VueConstructor<V>
  302. mixin(mixin: VueConstructor | ComponentOptions<Vue>): VueConstructor<V>
  303. compile(template: string): {
  304. render(createElement: typeof Vue.prototype.$createElement): VNode
  305. staticRenderFns: (() => VNode)[]
  306. }
  307. observable<T>(obj: T): T
  308. util: {
  309. warn(msg: string, vm?: InstanceType<VueConstructor>): void
  310. }
  311. config: VueConfiguration
  312. version: string
  313. }
  314. export const Vue: VueConstructor