vue.d.ts 11 KB

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