Skip to content

Commit 9d9f55d

Browse files
Add experimental typescript types
1 parent 3be0d85 commit 9d9f55d

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "Async computed properties for Vue",
55
"main": "dist/vue-async-computed.js",
66
"module": "dist/vue-async-computed.esm.js",
7+
"types": "types/index.d.ts",
78
"files": [
89
"bin/",
910
"dist/"

types/index.d.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import Vue, { PluginFunction } from "vue";
2+
3+
export interface IAsyncComputedOptions {
4+
errorHandler?: (error: string | Error) => void;
5+
useRawError?: boolean;
6+
default?: any;
7+
}
8+
9+
export default class AsyncComputed {
10+
constructor(options?: IAsyncComputedOptions);
11+
static install: PluginFunction<never>;
12+
static version: string;
13+
}
14+
15+
type AsyncComputedGetter<T> = () => Promise<T>;
16+
interface IAsyncComputedValue<T> {
17+
default?: T | (() => T);
18+
get: AsyncComputedGetter<T>;
19+
watch?: () => void;
20+
shouldUpdate?: () => boolean;
21+
lazy?: boolean;
22+
}
23+
24+
interface AsyncComputedObject {
25+
[K: string]: AsyncComputedGetter<any> | IAsyncComputedValue<any>;
26+
}
27+
28+
declare module "vue/types/options" {
29+
interface ComponentOptions<V extends Vue> {
30+
asyncComputed?: AsyncComputedObject;
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+
interface Vue {
45+
$asyncComputed: { [K: string]: IASyncComputedState };
46+
}
47+
}

0 commit comments

Comments
 (0)