vue.d.ts 8.6 KB

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