Skip to content

Commit 8abb270

Browse files
committed
added TypeScript typings
resolves #25
1 parent 0e6fa13 commit 8abb270

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "3.5.0",
44
"description": "Async computed properties for Vue",
55
"main": "dist/vue-async-computed.js",
6+
"types": "types/index.d.ts",
67
"files": [
78
"bin/",
89
"dist/"

Diff for: types/index.d.ts

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import Vue, { PluginFunction } from "vue";
2+
3+
export interface IAsyncComputedOptions {
4+
errorHandler?: (error: string | Error) => void;
5+
useRawError?: boolean;
6+
}
7+
8+
export default class AsyncComputed {
9+
constructor(options?: IAsyncComputedOptions)
10+
static install: PluginFunction<never>;
11+
static version: string;
12+
}
13+
14+
type AsyncComputedGetter<T> = () => Promise<T>;
15+
interface IAsyncComputedProperty<T> {
16+
default?: T | (() => T);
17+
get: AsyncComputedGetter<T>;
18+
watch?: () => void;
19+
shouldUpdate?: () => boolean;
20+
lazy?: boolean;
21+
}
22+
23+
interface IAsyncComputedProperties {
24+
[K: string]: AsyncComputedGetter<any> | IAsyncComputedProperty<any>;
25+
}
26+
27+
declare module "vue/types/options" {
28+
// tslint:disable-next-line:interface-name
29+
interface ComponentOptions<V extends Vue> {
30+
asyncComputed?: IAsyncComputedProperties;
31+
}
32+
}
33+
34+
interface IASyncComputedState {
35+
state: "updating" | "success" | "error";
36+
updating: boolean;
37+
success: boolean;
38+
error: boolean;
39+
exception: Error | null;
40+
update: () => void;
41+
}
42+
43+
declare module "vue/types/vue" {
44+
// tslint:disable-next-line:interface-name
45+
interface Vue {
46+
$asyncComputed: {[K: string]: IASyncComputedState };
47+
}
48+
}

0 commit comments

Comments
 (0)