vue.d.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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, ScopedSlot } from "./vnode";
  16. import { PluginFunction, PluginObject } from "./plugin";
  17. export interface CreateElement {
  18. (tag?: string | Component<any, any, any, any> | AsyncComponent<any, any, any, any>, children?: VNodeChildren): VNode;
  19. (tag?: string | Component<any, any, any, any> | AsyncComponent<any, any, any, any>, data?: VNodeData, children?: VNodeChildren): VNode;
  20. }
  21. export interface Vue {
  22. readonly $el: HTMLElement;
  23. readonly $options: ComponentOptions<Vue>;
  24. readonly $parent: Vue;
  25. readonly $root: Vue;
  26. readonly $children: Vue[];
  27. readonly $refs: { [key: string]: Vue | Element | Vue[] | Element[] };
  28. readonly $slots: { [key: string]: VNode[] };
  29. readonly $scopedSlots: { [key: string]: ScopedSlot };
  30. readonly $isServer: boolean;
  31. readonly $data: Record<string, any>;
  32. readonly $props: Record<string, any>;
  33. readonly $ssrContext: any;
  34. readonly $vnode: VNode;
  35. readonly $attrs: Record<string, string>;
  36. readonly $listeners: Record<string, Function | Function[]>;
  37. $mount(elementOrSelector?: Element | String, hydrating?: boolean): this;
  38. $forceUpdate(): void;
  39. $destroy(): void;
  40. $set: typeof Vue.set;
  41. $delete: typeof Vue.delete;
  42. $watch(
  43. expOrFn: string,
  44. callback: (this: this, n: any, o: any) => void,
  45. options?: WatchOptions
  46. ): (() => void);
  47. $watch<T>(
  48. expOrFn: (this: this) => T,
  49. callback: (this: this, n: T, o: T) => void,
  50. options?: WatchOptions
  51. ): (() => void);
  52. $on(event: string | string[], callback: Function): this;
  53. $once(event: string, callback: Function): this;
  54. $off(event?: string | string[], callback?: Function): this;
  55. $emit(event: string, ...args: any[]): this;
  56. $nextTick(callback: (this: this) => void): void;
  57. $nextTick(): Promise<void>;
  58. $createElement: CreateElement;
  59. }
  60. export type CombinedVueInstance<Instance extends Vue, Data, Methods, Computed, Props> = Data & Methods & Computed & Props & Instance;
  61. export type ExtendedVue<Instance extends Vue, Data, Methods, Computed, Props> = VueConstructor<CombinedVueInstance<Instance, Data, Methods, Computed, Props> & Vue>;
  62. export interface VueConstructor<V extends Vue = Vue> {
  63. new <Data = object, Methods = object, Computed = object, PropNames extends string = never>(options?: ThisTypedComponentOptionsWithArrayProps<V, Data, Methods, Computed, PropNames>): CombinedVueInstance<V, Data, Methods, Computed, Record<PropNames, any>>;
  64. // ideally, the return type should just contains Props, not Record<keyof Props, any>. But TS requires Base constructors must all have the same return type.
  65. new <Data = object, Methods = object, Computed = object, Props = object>(options?: ThisTypedComponentOptionsWithRecordProps<V, Data, Methods, Computed, Props>): CombinedVueInstance<V, Data, Methods, Computed, Record<keyof Props, any>>;
  66. new (options?: ComponentOptions<V>): CombinedVueInstance<V, object, object, object, Record<keyof object, any>>;
  67. extend<PropNames extends string = never>(definition: FunctionalComponentOptions<Record<PropNames, any>, PropNames[]>): ExtendedVue<V, {}, {}, {}, Record<PropNames, any>>;
  68. extend<Props>(definition: FunctionalComponentOptions<Props, RecordPropsDefinition<Props>>): ExtendedVue<V, {}, {}, {}, Props>;
  69. extend<Data, Methods, Computed, PropNames extends string>(options?: ThisTypedComponentOptionsWithArrayProps<V, Data, Methods, Computed, PropNames>): ExtendedVue<V, Data, Methods, Computed, Record<PropNames, any>>;
  70. extend<Data, Methods, Computed, Props>(options?: ThisTypedComponentOptionsWithRecordProps<V, Data, Methods, Computed, Props>): ExtendedVue<V, Data, Methods, Computed, Props>;
  71. extend(options?: ComponentOptions<V>): ExtendedVue<V, {}, {}, {}, {}>;
  72. nextTick(callback: () => void, context?: any[]): void;
  73. nextTick(): Promise<void>
  74. set<T>(object: Object, key: string, value: T): T;
  75. set<T>(array: T[], key: number, value: T): T;
  76. delete(object: Object, key: string): void;
  77. delete<T>(array: T[], key: number): void;
  78. directive(
  79. id: string,
  80. definition?: DirectiveOptions | DirectiveFunction
  81. ): DirectiveOptions;
  82. filter(id: string, definition?: Function): Function;
  83. component(id: string): VueConstructor;
  84. component<VC extends VueConstructor>(id: string, constructor: VC): VC;
  85. component<Data, Methods, Computed, Props>(id: string, definition: AsyncComponent<Data, Methods, Computed, Props>): ExtendedVue<V, Data, Methods, Computed, Props>;
  86. component<PropNames extends string>(id: string, definition: FunctionalComponentOptions<Record<PropNames, any>, PropNames[]>): ExtendedVue<V, {}, {}, {}, Record<PropNames, any>>;
  87. component<Props>(id: string, definition: FunctionalComponentOptions<Props, RecordPropsDefinition<Props>>): ExtendedVue<V, {}, {}, {}, Props>;
  88. component<Data, Methods, Computed, PropNames extends string>(id: string, definition?: ThisTypedComponentOptionsWithArrayProps<V, Data, Methods, Computed, PropNames>): ExtendedVue<V, Data, Methods, Computed, Record<PropNames, any>>;
  89. component<Data, Methods, Computed, Props>(id: string, definition?: ThisTypedComponentOptionsWithRecordProps<V, Data, Methods, Computed, Props>): ExtendedVue<V, Data, Methods, Computed, Props>;
  90. component(id: string, definition?: ComponentOptions<V>): ExtendedVue<V, {}, {}, {}, {}>;
  91. use<T>(plugin: PluginObject<T> | PluginFunction<T>, options?: T): void;
  92. use(plugin: PluginObject<any> | PluginFunction<any>, ...options: any[]): void;
  93. mixin(mixin: VueConstructor | ComponentOptions<Vue>): void;
  94. compile(template: string): {
  95. render(createElement: typeof Vue.prototype.$createElement): VNode;
  96. staticRenderFns: (() => VNode)[];
  97. };
  98. config: {
  99. silent: boolean;
  100. optionMergeStrategies: any;
  101. devtools: boolean;
  102. productionTip: boolean;
  103. performance: boolean;
  104. errorHandler(err: Error, vm: Vue, info: string): void;
  105. warnHandler(msg: string, vm: Vue, trace: string): void;
  106. ignoredElements: (string | RegExp)[];
  107. keyCodes: { [key: string]: number | number[] };
  108. }
  109. }
  110. export const Vue: VueConstructor;