2017-10-06 18:45:14 +00:00
|
|
|
import { Vue, CreateElement, CombinedVueInstance } from "./vue";
|
2016-09-06 13:28:17 +00:00
|
|
|
import { VNode, VNodeData, VNodeDirective } from "./vnode";
|
2016-08-23 19:01:30 +00:00
|
|
|
|
|
|
|
type Constructor = {
|
|
|
|
new (...args: any[]): any;
|
|
|
|
}
|
|
|
|
|
2017-10-06 18:45:14 +00:00
|
|
|
// we don't support infer props in async component
|
2018-01-03 06:33:48 +00:00
|
|
|
// N.B. ComponentOptions<V> is contravariant, the default generic should be bottom type
|
|
|
|
export type Component<Data=DefaultData<never>, Methods=DefaultMethods<never>, Computed=DefaultComputed, Props=DefaultProps> =
|
2017-10-06 18:45:14 +00:00
|
|
|
| typeof Vue
|
|
|
|
| FunctionalComponentOptions<Props>
|
2018-01-03 06:33:48 +00:00
|
|
|
| ComponentOptions<never, Data, Methods, Computed, Props>
|
2017-09-05 19:25:16 +00:00
|
|
|
|
|
|
|
interface EsModuleComponent {
|
|
|
|
default: Component
|
|
|
|
}
|
|
|
|
|
2018-01-03 06:33:48 +00:00
|
|
|
export type AsyncComponent<Data=DefaultData<never>, Methods=DefaultMethods<never>, Computed=DefaultComputed, Props=DefaultProps> = (
|
2017-10-06 18:45:14 +00:00
|
|
|
resolve: (component: Component<Data, Methods, Computed, Props>) => void,
|
2016-09-30 17:57:38 +00:00
|
|
|
reject: (reason?: any) => void
|
2017-10-06 18:45:14 +00:00
|
|
|
) => Promise<Component | EsModuleComponent> | void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When the `Computed` type parameter on `ComponentOptions` is inferred,
|
|
|
|
* it should have a property with the return type of every get-accessor.
|
|
|
|
* Since there isn't a way to query for the return type of a function, we allow TypeScript
|
|
|
|
* to infer from the shape of `Accessors<Computed>` and work backwards.
|
|
|
|
*/
|
|
|
|
export type Accessors<T> = {
|
|
|
|
[K in keyof T]: (() => T[K]) | ComputedOptions<T[K]>
|
|
|
|
}
|
2016-09-30 17:57:38 +00:00
|
|
|
|
2018-03-08 18:55:52 +00:00
|
|
|
type DataDef<Data, Props, V> = Data | ((this: Readonly<Props> & V) => Data)
|
2017-10-06 18:45:14 +00:00
|
|
|
/**
|
|
|
|
* This type should be used when an array of strings is used for a component's `props` value.
|
|
|
|
*/
|
|
|
|
export type ThisTypedComponentOptionsWithArrayProps<V extends Vue, Data, Methods, Computed, PropNames extends string> =
|
|
|
|
object &
|
2018-03-08 18:55:52 +00:00
|
|
|
ComponentOptions<V, DataDef<Data, Record<PropNames, any>, V>, Methods, Computed, PropNames[], Record<PropNames, any>> &
|
2017-10-06 18:45:14 +00:00
|
|
|
ThisType<CombinedVueInstance<V, Data, Methods, Computed, Readonly<Record<PropNames, any>>>>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This type should be used when an object mapped to `PropOptions` is used for a component's `props` value.
|
|
|
|
*/
|
|
|
|
export type ThisTypedComponentOptionsWithRecordProps<V extends Vue, Data, Methods, Computed, Props> =
|
|
|
|
object &
|
2018-03-08 18:55:52 +00:00
|
|
|
ComponentOptions<V, DataDef<Data, Props, V>, Methods, Computed, RecordPropsDefinition<Props>, Props> &
|
2017-10-06 18:45:14 +00:00
|
|
|
ThisType<CombinedVueInstance<V, Data, Methods, Computed, Readonly<Props>>>;
|
|
|
|
|
|
|
|
type DefaultData<V> = object | ((this: V) => object);
|
|
|
|
type DefaultProps = Record<string, any>;
|
|
|
|
type DefaultMethods<V> = { [key: string]: (this: V, ...args: any[]) => any };
|
|
|
|
type DefaultComputed = { [key: string]: any };
|
|
|
|
export interface ComponentOptions<
|
|
|
|
V extends Vue,
|
|
|
|
Data=DefaultData<V>,
|
|
|
|
Methods=DefaultMethods<V>,
|
|
|
|
Computed=DefaultComputed,
|
2018-03-08 18:55:52 +00:00
|
|
|
PropsDef=PropsDefinition<DefaultProps>,
|
|
|
|
Props=DefaultProps> {
|
2017-10-06 18:45:14 +00:00
|
|
|
data?: Data;
|
|
|
|
props?: PropsDef;
|
2017-11-27 14:30:58 +00:00
|
|
|
propsData?: object;
|
2017-10-06 18:45:14 +00:00
|
|
|
computed?: Accessors<Computed>;
|
|
|
|
methods?: Methods;
|
|
|
|
watch?: Record<string, WatchOptionsWithHandler<any> | WatchHandler<any> | string>;
|
2016-08-23 19:01:30 +00:00
|
|
|
|
2017-11-27 14:30:58 +00:00
|
|
|
el?: Element | string;
|
2016-08-23 19:01:30 +00:00
|
|
|
template?: string;
|
2018-03-08 18:55:52 +00:00
|
|
|
// hack is for funcitonal component type inference, should not used in user code
|
|
|
|
render?(createElement: CreateElement, hack: RenderContext<Props>): VNode;
|
2018-12-01 04:28:29 +00:00
|
|
|
renderError?(createElement: CreateElement, err: Error): VNode;
|
2016-10-08 18:15:36 +00:00
|
|
|
staticRenderFns?: ((createElement: CreateElement) => VNode)[];
|
2016-08-23 19:01:30 +00:00
|
|
|
|
2016-09-13 23:59:14 +00:00
|
|
|
beforeCreate?(this: V): void;
|
2017-10-06 18:45:14 +00:00
|
|
|
created?(): void;
|
|
|
|
beforeDestroy?(): void;
|
|
|
|
destroyed?(): void;
|
|
|
|
beforeMount?(): void;
|
|
|
|
mounted?(): void;
|
|
|
|
beforeUpdate?(): void;
|
|
|
|
updated?(): void;
|
|
|
|
activated?(): void;
|
|
|
|
deactivated?(): void;
|
2018-03-08 17:05:03 +00:00
|
|
|
errorCaptured?(err: Error, vm: Vue, info: string): boolean | void;
|
2017-10-06 18:45:14 +00:00
|
|
|
|
|
|
|
directives?: { [key: string]: DirectiveFunction | DirectiveOptions };
|
|
|
|
components?: { [key: string]: Component<any, any, any, any> | AsyncComponent<any, any, any, any> };
|
2017-11-27 14:30:58 +00:00
|
|
|
transitions?: { [key: string]: object };
|
2016-08-23 19:01:30 +00:00
|
|
|
filters?: { [key: string]: Function };
|
|
|
|
|
2017-11-27 14:30:58 +00:00
|
|
|
provide?: object | (() => object);
|
2017-10-06 21:41:54 +00:00
|
|
|
inject?: InjectOptions;
|
2017-02-22 03:35:50 +00:00
|
|
|
|
|
|
|
model?: {
|
|
|
|
prop?: string;
|
|
|
|
event?: string;
|
|
|
|
};
|
|
|
|
|
2016-08-23 19:01:30 +00:00
|
|
|
parent?: Vue;
|
2016-09-13 23:59:14 +00:00
|
|
|
mixins?: (ComponentOptions<Vue> | typeof Vue)[];
|
2016-08-23 19:01:30 +00:00
|
|
|
name?: string;
|
2017-10-06 18:45:14 +00:00
|
|
|
// TODO: support properly inferred 'extends'
|
2016-09-13 23:59:14 +00:00
|
|
|
extends?: ComponentOptions<Vue> | typeof Vue;
|
2016-08-23 19:01:30 +00:00
|
|
|
delimiters?: [string, string];
|
2017-06-30 00:56:23 +00:00
|
|
|
comments?: boolean;
|
2017-07-11 14:43:31 +00:00
|
|
|
inheritAttrs?: boolean;
|
2016-08-23 19:01:30 +00:00
|
|
|
}
|
|
|
|
|
2017-10-06 18:45:14 +00:00
|
|
|
export interface FunctionalComponentOptions<Props = DefaultProps, PropDefs = PropsDefinition<Props>> {
|
2017-06-13 09:49:52 +00:00
|
|
|
name?: string;
|
2017-10-06 18:45:14 +00:00
|
|
|
props?: PropDefs;
|
2018-10-24 17:03:48 +00:00
|
|
|
model?: {
|
|
|
|
prop?: string;
|
|
|
|
event?: string;
|
|
|
|
};
|
2017-10-06 21:41:54 +00:00
|
|
|
inject?: InjectOptions;
|
2016-09-05 10:53:34 +00:00
|
|
|
functional: boolean;
|
2018-10-24 17:03:29 +00:00
|
|
|
render?(this: undefined, createElement: CreateElement, context: RenderContext<Props>): VNode | VNode[];
|
2016-09-05 10:53:34 +00:00
|
|
|
}
|
|
|
|
|
2017-10-06 18:45:14 +00:00
|
|
|
export interface RenderContext<Props=DefaultProps> {
|
|
|
|
props: Props;
|
2016-09-05 10:53:34 +00:00
|
|
|
children: VNode[];
|
2016-11-03 17:07:07 +00:00
|
|
|
slots(): any;
|
2016-09-05 10:53:34 +00:00
|
|
|
data: VNodeData;
|
|
|
|
parent: Vue;
|
2018-03-08 16:52:01 +00:00
|
|
|
listeners: { [key: string]: Function | Function[] };
|
2017-04-05 06:36:15 +00:00
|
|
|
injections: any
|
2016-09-05 10:53:34 +00:00
|
|
|
}
|
|
|
|
|
2017-10-06 18:45:14 +00:00
|
|
|
export type Prop<T> = { (): T } | { new (...args: any[]): T & object }
|
|
|
|
|
|
|
|
export type PropValidator<T> = PropOptions<T> | Prop<T> | Prop<T>[];
|
|
|
|
|
|
|
|
export interface PropOptions<T=any> {
|
|
|
|
type?: Prop<T> | Prop<T>[];
|
2016-08-23 19:01:30 +00:00
|
|
|
required?: boolean;
|
2018-09-18 02:33:58 +00:00
|
|
|
default?: T | null | undefined | (() => T | null | undefined);
|
2017-10-06 18:45:14 +00:00
|
|
|
validator?(value: T): boolean;
|
2016-08-23 19:01:30 +00:00
|
|
|
}
|
|
|
|
|
2017-10-06 18:45:14 +00:00
|
|
|
export type RecordPropsDefinition<T> = {
|
|
|
|
[K in keyof T]: PropValidator<T[K]>
|
|
|
|
}
|
|
|
|
export type ArrayPropsDefinition<T> = (keyof T)[];
|
|
|
|
export type PropsDefinition<T> = ArrayPropsDefinition<T> | RecordPropsDefinition<T>;
|
|
|
|
|
|
|
|
export interface ComputedOptions<T> {
|
|
|
|
get?(): T;
|
|
|
|
set?(value: T): void;
|
2016-08-23 19:01:30 +00:00
|
|
|
cache?: boolean;
|
|
|
|
}
|
|
|
|
|
2017-10-06 18:45:14 +00:00
|
|
|
export type WatchHandler<T> = (val: T, oldVal: T) => void;
|
2016-08-23 19:01:30 +00:00
|
|
|
|
|
|
|
export interface WatchOptions {
|
|
|
|
deep?: boolean;
|
|
|
|
immediate?: boolean;
|
|
|
|
}
|
|
|
|
|
2017-10-06 18:45:14 +00:00
|
|
|
export interface WatchOptionsWithHandler<T> extends WatchOptions {
|
|
|
|
handler: WatchHandler<T>;
|
|
|
|
}
|
|
|
|
|
2018-10-22 20:09:23 +00:00
|
|
|
export interface DirectiveBinding extends Readonly<VNodeDirective> {
|
|
|
|
readonly modifiers: { [key: string]: boolean };
|
|
|
|
}
|
|
|
|
|
2016-08-23 19:01:30 +00:00
|
|
|
export type DirectiveFunction = (
|
|
|
|
el: HTMLElement,
|
2018-10-22 20:09:23 +00:00
|
|
|
binding: DirectiveBinding,
|
2016-08-23 19:01:30 +00:00
|
|
|
vnode: VNode,
|
|
|
|
oldVnode: VNode
|
|
|
|
) => void;
|
|
|
|
|
|
|
|
export interface DirectiveOptions {
|
|
|
|
bind?: DirectiveFunction;
|
2016-09-16 16:40:13 +00:00
|
|
|
inserted?: DirectiveFunction;
|
2016-08-23 19:01:30 +00:00
|
|
|
update?: DirectiveFunction;
|
|
|
|
componentUpdated?: DirectiveFunction;
|
|
|
|
unbind?: DirectiveFunction;
|
|
|
|
}
|
2017-10-06 21:41:54 +00:00
|
|
|
|
|
|
|
export type InjectKey = string | symbol;
|
|
|
|
|
|
|
|
export type InjectOptions = {
|
|
|
|
[key: string]: InjectKey | { from?: InjectKey, default?: any }
|
|
|
|
} | string[];
|