vue.d.ts 11 KB

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