UNPKG

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