2017-10-07 02:45:14 +08:00
|
|
|
import { Vue, CreateElement, CombinedVueInstance } from "./vue";
|
2016-09-06 21:28:17 +08:00
|
|
|
import { VNode, VNodeData, VNodeDirective } from "./vnode";
|
2016-08-24 03:01:30 +08:00
|
|
|
|
|
|
|
type Constructor = {
|
|
|
|
new (...args: any[]): any;
|
|
|
|
}
|
|
|
|
|
2017-10-07 02:45:14 +08:00
|
|
|
// we don't support infer props in async component
|
|
|
|
export type Component<Data=DefaultData<Vue>, Methods=DefaultMethods<Vue>, Computed=DefaultComputed, Props=DefaultProps> =
|
|
|
|
| typeof Vue
|
|
|
|
| FunctionalComponentOptions<Props>
|
|
|
|
| ThisTypedComponentOptionsWithArrayProps<Vue, Data, Methods, Computed, keyof Props>
|
|
|
|
| ThisTypedComponentOptionsWithRecordProps<Vue, Data, Methods, Computed, Props>;
|
2017-09-06 03:25:16 +08:00
|
|
|
|
|
|
|
interface EsModuleComponent {
|
|
|
|
default: Component
|
|
|
|
}
|
|
|
|
|
2017-10-07 02:45:14 +08:00
|
|
|
export type AsyncComponent<Data=DefaultData<Vue>, Methods=DefaultMethods<Vue>, Computed=DefaultComputed, Props=DefaultProps> = (
|
|
|
|
resolve: (component: Component<Data, Methods, Computed, Props>) => void,
|
2016-10-01 01:57:38 +08:00
|
|
|
reject: (reason?: any) => void
|
2017-10-07 02:45:14 +08: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-10-01 01:57:38 +08:00
|
|
|
|
2017-10-07 02:45:14 +08: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 &
|
|
|
|
ComponentOptions<V, Data | ((this: Readonly<Record<PropNames, any>> & V) => Data), Methods, Computed, PropNames[]> &
|
|
|
|
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 &
|
|
|
|
ComponentOptions<V, Data | ((this: Readonly<Props> & V) => Data), Methods, Computed, RecordPropsDefinition<Props>> &
|
|
|
|
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,
|
|
|
|
PropsDef=PropsDefinition<DefaultProps>> {
|
|
|
|
data?: Data;
|
|
|
|
props?: PropsDef;
|
2016-08-24 03:01:30 +08:00
|
|
|
propsData?: Object;
|
2017-10-07 02:45:14 +08:00
|
|
|
computed?: Accessors<Computed>;
|
|
|
|
methods?: Methods;
|
|
|
|
watch?: Record<string, WatchOptionsWithHandler<any> | WatchHandler<any> | string>;
|
2016-08-24 03:01:30 +08:00
|
|
|
|
|
|
|
el?: Element | String;
|
|
|
|
template?: string;
|
2017-10-07 02:45:14 +08:00
|
|
|
render?(createElement: CreateElement): VNode;
|
2017-02-23 02:17:18 +08:00
|
|
|
renderError?: (h: () => VNode, err: Error) => VNode;
|
2016-10-09 02:15:36 +08:00
|
|
|
staticRenderFns?: ((createElement: CreateElement) => VNode)[];
|
2016-08-24 03:01:30 +08:00
|
|
|
|
2016-09-14 07:59:14 +08:00
|
|
|
beforeCreate?(this: V): void;
|
2017-10-07 02:45:14 +08:00
|
|
|
created?(): void;
|
|
|
|
beforeDestroy?(): void;
|
|
|
|
destroyed?(): void;
|
|
|
|
beforeMount?(): void;
|
|
|
|
mounted?(): void;
|
|
|
|
beforeUpdate?(): void;
|
|
|
|
updated?(): void;
|
|
|
|
activated?(): void;
|
|
|
|
deactivated?(): void;
|
2017-10-07 05:41:54 +08:00
|
|
|
errorCaptured?(): boolean | void;
|
2017-10-07 02:45:14 +08:00
|
|
|
|
|
|
|
directives?: { [key: string]: DirectiveFunction | DirectiveOptions };
|
|
|
|
components?: { [key: string]: Component<any, any, any, any> | AsyncComponent<any, any, any, any> };
|
2016-08-24 03:01:30 +08:00
|
|
|
transitions?: { [key: string]: Object };
|
|
|
|
filters?: { [key: string]: Function };
|
|
|
|
|
2017-02-22 11:35:50 +08:00
|
|
|
provide?: Object | (() => Object);
|
2017-10-07 05:41:54 +08:00
|
|
|
inject?: InjectOptions;
|
2017-02-22 11:35:50 +08:00
|
|
|
|
|
|
|
model?: {
|
|
|
|
prop?: string;
|
|
|
|
event?: string;
|
|
|
|
};
|
|
|
|
|
2016-08-24 03:01:30 +08:00
|
|
|
parent?: Vue;
|
2016-09-14 07:59:14 +08:00
|
|
|
mixins?: (ComponentOptions<Vue> | typeof Vue)[];
|
2016-08-24 03:01:30 +08:00
|
|
|
name?: string;
|
2017-10-07 02:45:14 +08:00
|
|
|
// TODO: support properly inferred 'extends'
|
2016-09-14 07:59:14 +08:00
|
|
|
extends?: ComponentOptions<Vue> | typeof Vue;
|
2016-08-24 03:01:30 +08:00
|
|
|
delimiters?: [string, string];
|
2017-06-30 08:56:23 +08:00
|
|
|
comments?: boolean;
|
2017-07-11 22:43:31 +08:00
|
|
|
inheritAttrs?: boolean;
|
2016-08-24 03:01:30 +08:00
|
|
|
}
|
|
|
|
|
2017-10-07 02:45:14 +08:00
|
|
|
export interface FunctionalComponentOptions<Props = DefaultProps, PropDefs = PropsDefinition<Props>> {
|
2017-06-13 17:49:52 +08:00
|
|
|
name?: string;
|
2017-10-07 02:45:14 +08:00
|
|
|
props?: PropDefs;
|
2017-10-07 05:41:54 +08:00
|
|
|
inject?: InjectOptions;
|
2016-09-05 18:53:34 +08:00
|
|
|
functional: boolean;
|
2017-10-07 02:45:14 +08:00
|
|
|
render(this: undefined, createElement: CreateElement, context: RenderContext<Props>): VNode;
|
2016-09-05 18:53:34 +08:00
|
|
|
}
|
|
|
|
|
2017-10-07 02:45:14 +08:00
|
|
|
export interface RenderContext<Props=DefaultProps> {
|
|
|
|
props: Props;
|
2016-09-05 18:53:34 +08:00
|
|
|
children: VNode[];
|
2016-11-04 01:07:07 +08:00
|
|
|
slots(): any;
|
2016-09-05 18:53:34 +08:00
|
|
|
data: VNodeData;
|
|
|
|
parent: Vue;
|
2017-04-05 14:36:15 +08:00
|
|
|
injections: any
|
2016-09-05 18:53:34 +08:00
|
|
|
}
|
|
|
|
|
2017-10-07 02:45:14 +08: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-24 03:01:30 +08:00
|
|
|
required?: boolean;
|
2017-10-07 02:45:14 +08:00
|
|
|
default?: T | null | undefined | (() => object);
|
|
|
|
validator?(value: T): boolean;
|
2016-08-24 03:01:30 +08:00
|
|
|
}
|
|
|
|
|
2017-10-07 02:45:14 +08: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-24 03:01:30 +08:00
|
|
|
cache?: boolean;
|
|
|
|
}
|
|
|
|
|
2017-10-07 02:45:14 +08:00
|
|
|
export type WatchHandler<T> = (val: T, oldVal: T) => void;
|
2016-08-24 03:01:30 +08:00
|
|
|
|
|
|
|
export interface WatchOptions {
|
|
|
|
deep?: boolean;
|
|
|
|
immediate?: boolean;
|
|
|
|
}
|
|
|
|
|
2017-10-07 02:45:14 +08:00
|
|
|
export interface WatchOptionsWithHandler<T> extends WatchOptions {
|
|
|
|
handler: WatchHandler<T>;
|
|
|
|
}
|
|
|
|
|
2016-08-24 03:01:30 +08:00
|
|
|
export type DirectiveFunction = (
|
|
|
|
el: HTMLElement,
|
|
|
|
binding: VNodeDirective,
|
|
|
|
vnode: VNode,
|
|
|
|
oldVnode: VNode
|
|
|
|
) => void;
|
|
|
|
|
|
|
|
export interface DirectiveOptions {
|
|
|
|
bind?: DirectiveFunction;
|
2016-09-17 00:40:13 +08:00
|
|
|
inserted?: DirectiveFunction;
|
2016-08-24 03:01:30 +08:00
|
|
|
update?: DirectiveFunction;
|
|
|
|
componentUpdated?: DirectiveFunction;
|
|
|
|
unbind?: DirectiveFunction;
|
|
|
|
}
|
2017-10-07 05:41:54 +08:00
|
|
|
|
|
|
|
export type InjectKey = string | symbol;
|
|
|
|
|
|
|
|
export type InjectOptions = {
|
|
|
|
[key: string]: InjectKey | { from?: InjectKey, default?: any }
|
|
|
|
} | string[];
|