import { Vue, CreateElement, CombinedVueInstance } from "./vue"; import { VNode, VNodeData, VNodeDirective } from "./vnode"; type Constructor = { new (...args: any[]): any; } // we don't support infer props in async component export type Component, Methods=DefaultMethods, Computed=DefaultComputed, Props=DefaultProps> = | typeof Vue | FunctionalComponentOptions | ThisTypedComponentOptionsWithArrayProps | ThisTypedComponentOptionsWithRecordProps; interface EsModuleComponent { default: Component } export type AsyncComponent, Methods=DefaultMethods, Computed=DefaultComputed, Props=DefaultProps> = ( resolve: (component: Component) => void, reject: (reason?: any) => void ) => Promise | 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` and work backwards. */ export type Accessors = { [K in keyof T]: (() => T[K]) | ComputedOptions } /** * This type should be used when an array of strings is used for a component's `props` value. */ export type ThisTypedComponentOptionsWithArrayProps = object & ComponentOptions> & V) => Data), Methods, Computed, PropNames[]> & ThisType>>>; /** * This type should be used when an object mapped to `PropOptions` is used for a component's `props` value. */ export type ThisTypedComponentOptionsWithRecordProps = object & ComponentOptions & V) => Data), Methods, Computed, RecordPropsDefinition> & ThisType>>; type DefaultData = object | ((this: V) => object); type DefaultProps = Record; type DefaultMethods = { [key: string]: (this: V, ...args: any[]) => any }; type DefaultComputed = { [key: string]: any }; export interface ComponentOptions< V extends Vue, Data=DefaultData, Methods=DefaultMethods, Computed=DefaultComputed, PropsDef=PropsDefinition> { data?: Data; props?: PropsDef; propsData?: Object; computed?: Accessors; methods?: Methods; watch?: Record | WatchHandler | string>; el?: Element | String; template?: string; render?(createElement: CreateElement): VNode; renderError?: (h: () => VNode, err: Error) => VNode; staticRenderFns?: ((createElement: CreateElement) => VNode)[]; beforeCreate?(this: V): void; created?(): void; beforeDestroy?(): void; destroyed?(): void; beforeMount?(): void; mounted?(): void; beforeUpdate?(): void; updated?(): void; activated?(): void; deactivated?(): void; errorCaptured?(): boolean | void; directives?: { [key: string]: DirectiveFunction | DirectiveOptions }; components?: { [key: string]: Component | AsyncComponent }; transitions?: { [key: string]: Object }; filters?: { [key: string]: Function }; provide?: Object | (() => Object); inject?: InjectOptions; model?: { prop?: string; event?: string; }; parent?: Vue; mixins?: (ComponentOptions | typeof Vue)[]; name?: string; // TODO: support properly inferred 'extends' extends?: ComponentOptions | typeof Vue; delimiters?: [string, string]; comments?: boolean; inheritAttrs?: boolean; } export interface FunctionalComponentOptions> { name?: string; props?: PropDefs; inject?: InjectOptions; functional: boolean; render(this: undefined, createElement: CreateElement, context: RenderContext): VNode; } export interface RenderContext { props: Props; children: VNode[]; slots(): any; data: VNodeData; parent: Vue; injections: any } export type Prop = { (): T } | { new (...args: any[]): T & object } export type PropValidator = PropOptions | Prop | Prop[]; export interface PropOptions { type?: Prop | Prop[]; required?: boolean; default?: T | null | undefined | (() => object); validator?(value: T): boolean; } export type RecordPropsDefinition = { [K in keyof T]: PropValidator } export type ArrayPropsDefinition = (keyof T)[]; export type PropsDefinition = ArrayPropsDefinition | RecordPropsDefinition; export interface ComputedOptions { get?(): T; set?(value: T): void; cache?: boolean; } export type WatchHandler = (val: T, oldVal: T) => void; export interface WatchOptions { deep?: boolean; immediate?: boolean; } export interface WatchOptionsWithHandler extends WatchOptions { handler: WatchHandler; } export type DirectiveFunction = ( el: HTMLElement, binding: VNodeDirective, vnode: VNode, oldVnode: VNode ) => void; export interface DirectiveOptions { bind?: DirectiveFunction; inserted?: DirectiveFunction; update?: DirectiveFunction; componentUpdated?: DirectiveFunction; unbind?: DirectiveFunction; } export type InjectKey = string | symbol; export type InjectOptions = { [key: string]: InjectKey | { from?: InjectKey, default?: any } } | string[];