Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Vue, { PluginFunction } from 'vue';
import { PluginFunction } from 'vue';
import { ComponentOptions, DataDef, RecordPropsDefinition } from 'vue/types/options';

export interface IAsyncComputedOptions {
errorHandler?: (error: string | Error) => void;
Expand All @@ -25,10 +26,6 @@ export interface IAsyncComputedValue<T> extends IAsyncComputedValueBase<T> {
get: AsyncComputedGetter<T>;
}

export interface AsyncComputedObject {
[K: string]: AsyncComputedGetter<any> | IAsyncComputedValue<any>;
}

export interface IASyncComputedState {
state: 'updating' | 'success' | 'error';
updating: boolean;
Expand All @@ -38,14 +35,33 @@ export interface IASyncComputedState {
update: () => void;
}

declare module 'vue/types/options' {
interface ComponentOptions<V extends Vue> {
asyncComputed?: AsyncComputedObject;
}

export type AsyncComputedObject <T> = {
[K in keyof T] : AsyncComputedGetter<T[K]> | IAsyncComputedValue<T[K]>;
}

export type AsyncComputedStates<T> = {
$asyncComputed: {[K in keyof T]: IASyncComputedState};
}

export interface AsyncComputedOption <T> {
asyncComputed?: AsyncComputedObject<T>;
}

declare module 'vue/types/vue' {
interface Vue {
$asyncComputed: {[K: string]: IASyncComputedState};
interface VueConstructor<V extends Vue = Vue> {
extend<Data, Methods, Computed, PropNames extends string = never, AsyncComputed = {}>(options?:
object &
ComponentOptions<V, DataDef<Data, Record<PropNames, any>, V>, Methods, Computed, PropNames[], Record<PropNames, any>> &
AsyncComputedOption<AsyncComputed> &
ThisType<CombinedVueInstance<V, Data, Methods, Computed & AsyncComputed & AsyncComputedStates<AsyncComputed>, Readonly<Record<PropNames, any>>>>
): ExtendedVue<V, Data, Methods, Computed & AsyncComputed & AsyncComputedStates<AsyncComputed>, Record<PropNames, any>>;

extend<Data, Methods, Computed, Props, AsyncComputed = {}>(options?:
object &
ComponentOptions<V, DataDef<Data, Props, V>, Methods, Computed, RecordPropsDefinition<Props>, Props> &
AsyncComputedOption<AsyncComputed> &
ThisType<CombinedVueInstance<V, Data, Methods, Computed & AsyncComputed & AsyncComputedStates<AsyncComputed>, Readonly<Props>>>
): ExtendedVue<V, Data, Methods, Computed & AsyncComputed & AsyncComputedStates<AsyncComputed>, Props>;
}
}