diff options
| author | ruki <waruqi@gmail.com> | 2018-11-08 00:38:48 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2018-11-07 21:53:09 +0800 |
| commit | 26105034da4fcce7ac883c899d781f016559310d (patch) | |
| tree | c459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/vue/types | |
| parent | 2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff) | |
| download | xmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip | |
switch to vuepress
Diffstat (limited to 'node_modules/vue/types')
| -rw-r--r-- | node_modules/vue/types/index.d.ts | 37 | ||||
| -rw-r--r-- | node_modules/vue/types/options.d.ts | 182 | ||||
| -rw-r--r-- | node_modules/vue/types/plugin.d.ts | 8 | ||||
| -rw-r--r-- | node_modules/vue/types/vnode.d.ts | 67 | ||||
| -rw-r--r-- | node_modules/vue/types/vue.d.ts | 124 |
5 files changed, 418 insertions, 0 deletions
diff --git a/node_modules/vue/types/index.d.ts b/node_modules/vue/types/index.d.ts new file mode 100644 index 00000000..720180d2 --- /dev/null +++ b/node_modules/vue/types/index.d.ts @@ -0,0 +1,37 @@ +import { Vue } from "./vue"; + +export default Vue; + +export { + CreateElement, + VueConstructor +} from "./vue"; + +export { + Component, + AsyncComponent, + ComponentOptions, + FunctionalComponentOptions, + RenderContext, + PropOptions, + ComputedOptions, + WatchHandler, + WatchOptions, + WatchOptionsWithHandler, + DirectiveFunction, + DirectiveOptions +} from "./options"; + +export { + PluginFunction, + PluginObject +} from "./plugin"; + +export { + VNodeChildren, + VNodeChildrenArrayContents, + VNode, + VNodeComponentOptions, + VNodeData, + VNodeDirective +} from "./vnode"; diff --git a/node_modules/vue/types/options.d.ts b/node_modules/vue/types/options.d.ts new file mode 100644 index 00000000..cc58affe --- /dev/null +++ b/node_modules/vue/types/options.d.ts @@ -0,0 +1,182 @@ +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 +// 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> = + | typeof Vue + | FunctionalComponentOptions<Props> + | ComponentOptions<never, Data, Methods, Computed, Props> + +interface EsModuleComponent { + default: Component +} + +export type AsyncComponent<Data=DefaultData<never>, Methods=DefaultMethods<never>, Computed=DefaultComputed, Props=DefaultProps> = ( + resolve: (component: Component<Data, Methods, Computed, Props>) => void, + reject: (reason?: any) => void +) => 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]> +} + +type DataDef<Data, Props, V> = Data | ((this: Readonly<Props> & V) => Data) +/** + * 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, DataDef<Data, Record<PropNames, any>, V>, Methods, Computed, PropNames[], Record<PropNames, any>> & + 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, DataDef<Data, Props, V>, Methods, Computed, RecordPropsDefinition<Props>, 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>, + Props=DefaultProps> { + data?: Data; + props?: PropsDef; + propsData?: object; + computed?: Accessors<Computed>; + methods?: Methods; + watch?: Record<string, WatchOptionsWithHandler<any> | WatchHandler<any> | string>; + + el?: Element | string; + template?: string; + // hack is for funcitonal component type inference, should not used in user code + render?(createElement: CreateElement, hack: RenderContext<Props>): 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?(err: Error, vm: Vue, info: string): boolean | void; + + directives?: { [key: string]: DirectiveFunction | DirectiveOptions }; + components?: { [key: string]: Component<any, any, any, any> | AsyncComponent<any, any, any, any> }; + transitions?: { [key: string]: object }; + filters?: { [key: string]: Function }; + + provide?: object | (() => object); + inject?: InjectOptions; + + model?: { + prop?: string; + event?: string; + }; + + parent?: Vue; + mixins?: (ComponentOptions<Vue> | typeof Vue)[]; + name?: string; + // TODO: support properly inferred 'extends' + extends?: ComponentOptions<Vue> | typeof Vue; + delimiters?: [string, string]; + comments?: boolean; + inheritAttrs?: boolean; +} + +export interface FunctionalComponentOptions<Props = DefaultProps, PropDefs = PropsDefinition<Props>> { + name?: string; + props?: PropDefs; + inject?: InjectOptions; + functional: boolean; + render?(this: undefined, createElement: CreateElement, context: RenderContext<Props>): VNode; +} + +export interface RenderContext<Props=DefaultProps> { + props: Props; + children: VNode[]; + slots(): any; + data: VNodeData; + parent: Vue; + listeners: { [key: string]: Function | Function[] }; + injections: any +} + +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>[]; + required?: boolean; + default?: T | null | undefined | (() => object); + validator?(value: T): boolean; +} + +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; + cache?: boolean; +} + +export type WatchHandler<T> = (val: T, oldVal: T) => void; + +export interface WatchOptions { + deep?: boolean; + immediate?: boolean; +} + +export interface WatchOptionsWithHandler<T> extends WatchOptions { + handler: WatchHandler<T>; +} + +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[]; diff --git a/node_modules/vue/types/plugin.d.ts b/node_modules/vue/types/plugin.d.ts new file mode 100644 index 00000000..5741f862 --- /dev/null +++ b/node_modules/vue/types/plugin.d.ts @@ -0,0 +1,8 @@ +import { Vue as _Vue } from "./vue"; + +export type PluginFunction<T> = (Vue: typeof _Vue, options?: T) => void; + +export interface PluginObject<T> { + install: PluginFunction<T>; + [key: string]: any; +} diff --git a/node_modules/vue/types/vnode.d.ts b/node_modules/vue/types/vnode.d.ts new file mode 100644 index 00000000..5754c433 --- /dev/null +++ b/node_modules/vue/types/vnode.d.ts @@ -0,0 +1,67 @@ +import { Vue } from "./vue"; + +export type ScopedSlot = (props: any) => VNodeChildrenArrayContents | string; + +export type VNodeChildren = VNodeChildrenArrayContents | [ScopedSlot] | string; +export interface VNodeChildrenArrayContents extends Array<VNode | string | VNodeChildrenArrayContents> {} + +export interface VNode { + tag?: string; + data?: VNodeData; + children?: VNode[]; + text?: string; + elm?: Node; + ns?: string; + context?: Vue; + key?: string | number; + componentOptions?: VNodeComponentOptions; + componentInstance?: Vue; + parent?: VNode; + raw?: boolean; + isStatic?: boolean; + isRootInsert: boolean; + isComment: boolean; +} + +export interface VNodeComponentOptions { + Ctor: typeof Vue; + propsData?: object; + listeners?: object; + children?: VNodeChildren; + tag?: string; +} + +export interface VNodeData { + key?: string | number; + slot?: string; + scopedSlots?: { [key: string]: ScopedSlot }; + ref?: string; + tag?: string; + staticClass?: string; + class?: any; + staticStyle?: { [key: string]: any }; + style?: object[] | object; + props?: { [key: string]: any }; + attrs?: { [key: string]: any }; + domProps?: { [key: string]: any }; + hook?: { [key: string]: Function }; + on?: { [key: string]: Function | Function[] }; + nativeOn?: { [key: string]: Function | Function[] }; + transition?: object; + show?: boolean; + inlineTemplate?: { + render: Function; + staticRenderFns: Function[]; + }; + directives?: VNodeDirective[]; + keepAlive?: boolean; +} + +export interface VNodeDirective { + readonly name: string; + readonly value: any; + readonly oldValue: any; + readonly expression: any; + readonly arg: string; + readonly modifiers: { [key: string]: boolean }; +} diff --git a/node_modules/vue/types/vue.d.ts b/node_modules/vue/types/vue.d.ts new file mode 100644 index 00000000..e0b29157 --- /dev/null +++ b/node_modules/vue/types/vue.d.ts @@ -0,0 +1,124 @@ +import { + Component, + AsyncComponent, + ComponentOptions, + FunctionalComponentOptions, + WatchOptionsWithHandler, + WatchHandler, + DirectiveOptions, + DirectiveFunction, + RecordPropsDefinition, + ThisTypedComponentOptionsWithArrayProps, + ThisTypedComponentOptionsWithRecordProps, + WatchOptions, +} from "./options"; +import { VNode, VNodeData, VNodeChildren, ScopedSlot } from "./vnode"; +import { PluginFunction, PluginObject } from "./plugin"; + +export interface CreateElement { + (tag?: string | Component<any, any, any, any> | AsyncComponent<any, any, any, any> | (() => Component), children?: VNodeChildren): VNode; + (tag?: string | Component<any, any, any, any> | AsyncComponent<any, any, any, any> | (() => Component), data?: VNodeData, children?: VNodeChildren): VNode; +} + +export interface Vue { + readonly $el: HTMLElement; + readonly $options: ComponentOptions<Vue>; + readonly $parent: Vue; + readonly $root: Vue; + readonly $children: Vue[]; + readonly $refs: { [key: string]: Vue | Element | Vue[] | Element[] }; + readonly $slots: { [key: string]: VNode[] }; + readonly $scopedSlots: { [key: string]: ScopedSlot }; + readonly $isServer: boolean; + readonly $data: Record<string, any>; + readonly $props: Record<string, any>; + readonly $ssrContext: any; + readonly $vnode: VNode; + readonly $attrs: Record<string, string>; + readonly $listeners: Record<string, Function | Function[]>; + + $mount(elementOrSelector?: Element | string, hydrating?: boolean): this; + $forceUpdate(): void; + $destroy(): void; + $set: typeof Vue.set; + $delete: typeof Vue.delete; + $watch( + expOrFn: string, + callback: (this: this, n: any, o: any) => void, + options?: WatchOptions + ): (() => void); + $watch<T>( + expOrFn: (this: this) => T, + callback: (this: this, n: T, o: T) => void, + options?: WatchOptions + ): (() => void); + $on(event: string | string[], callback: Function): this; + $once(event: string, callback: Function): this; + $off(event?: string | string[], callback?: Function): this; + $emit(event: string, ...args: any[]): this; + $nextTick(callback: (this: this) => void): void; + $nextTick(): Promise<void>; + $createElement: CreateElement; +} + +export type CombinedVueInstance<Instance extends Vue, Data, Methods, Computed, Props> = Data & Methods & Computed & Props & Instance; +export type ExtendedVue<Instance extends Vue, Data, Methods, Computed, Props> = VueConstructor<CombinedVueInstance<Instance, Data, Methods, Computed, Props> & Vue>; + +export interface VueConfiguration { + silent: boolean; + optionMergeStrategies: any; + devtools: boolean; + productionTip: boolean; + performance: boolean; + errorHandler(err: Error, vm: Vue, info: string): void; + warnHandler(msg: string, vm: Vue, trace: string): void; + ignoredElements: (string | RegExp)[]; + keyCodes: { [key: string]: number | number[] }; +} + +export interface VueConstructor<V extends Vue = Vue> { + 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>>; + // 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. + 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>>; + new (options?: ComponentOptions<V>): CombinedVueInstance<V, object, object, object, Record<keyof object, any>>; + + extend<Data, Methods, Computed, PropNames extends string = never>(options?: ThisTypedComponentOptionsWithArrayProps<V, Data, Methods, Computed, PropNames>): ExtendedVue<V, Data, Methods, Computed, Record<PropNames, any>>; + extend<Data, Methods, Computed, Props>(options?: ThisTypedComponentOptionsWithRecordProps<V, Data, Methods, Computed, Props>): ExtendedVue<V, Data, Methods, Computed, Props>; + extend<PropNames extends string = never>(definition: FunctionalComponentOptions<Record<PropNames, any>, PropNames[]>): ExtendedVue<V, {}, {}, {}, Record<PropNames, any>>; + extend<Props>(definition: FunctionalComponentOptions<Props, RecordPropsDefinition<Props>>): ExtendedVue<V, {}, {}, {}, Props>; + extend(options?: ComponentOptions<V>): ExtendedVue<V, {}, {}, {}, {}>; + + nextTick(callback: () => void, context?: any[]): void; + nextTick(): Promise<void> + set<T>(object: object, key: string, value: T): T; + set<T>(array: T[], key: number, value: T): T; + delete(object: object, key: string): void; + delete<T>(array: T[], key: number): void; + + directive( + id: string, + definition?: DirectiveOptions | DirectiveFunction + ): DirectiveOptions; + filter(id: string, definition?: Function): Function; + + component(id: string): VueConstructor; + component<VC extends VueConstructor>(id: string, constructor: VC): VC; + component<Data, Methods, Computed, Props>(id: string, definition: AsyncComponent<Data, Methods, Computed, Props>): ExtendedVue<V, Data, Methods, Computed, Props>; + 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>>; + component<Data, Methods, Computed, Props>(id: string, definition?: ThisTypedComponentOptionsWithRecordProps<V, Data, Methods, Computed, Props>): ExtendedVue<V, Data, Methods, Computed, Props>; + component<PropNames extends string>(id: string, definition: FunctionalComponentOptions<Record<PropNames, any>, PropNames[]>): ExtendedVue<V, {}, {}, {}, Record<PropNames, any>>; + component<Props>(id: string, definition: FunctionalComponentOptions<Props, RecordPropsDefinition<Props>>): ExtendedVue<V, {}, {}, {}, Props>; + component(id: string, definition?: ComponentOptions<V>): ExtendedVue<V, {}, {}, {}, {}>; + + use<T>(plugin: PluginObject<T> | PluginFunction<T>, options?: T): void; + use(plugin: PluginObject<any> | PluginFunction<any>, ...options: any[]): void; + mixin(mixin: VueConstructor | ComponentOptions<Vue>): void; + compile(template: string): { + render(createElement: typeof Vue.prototype.$createElement): VNode; + staticRenderFns: (() => VNode)[]; + }; + + config: VueConfiguration; +} + +export const Vue: VueConstructor; |
