From 7aee47ae0ea003e1212ff007f132256cd5868bc6 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Sat, 4 Feb 2023 18:38:09 +0800 Subject: [PATCH] type preparation --- globals.d.ts | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 globals.d.ts diff --git a/globals.d.ts b/globals.d.ts new file mode 100644 index 0000000..bafd627 --- /dev/null +++ b/globals.d.ts @@ -0,0 +1,44 @@ +interface BlessingGlobals { + base_url: string + site_name: string + locale: string + version: string + route: string + + t(key: string, params?: object): string + + fetch: { + get(url: string, params?: Record): Promise + post(url: string, data?: any): Promise + put(url: string, data?: any): Promise + del(url: string, data?: any): Promise + } + + event: { + on( + eventName: string | symbol, + listener: (...args: any[]) => any, + ): () => void + emit(eventName: string | symbol, payload?: object): void + } + + notify: { + showModal(options?: object): Promise<{ value: string }> + toast: Toast + } +} + +declare class Toast { + success(message: string): void + info(message: string): void + warning(message: string): void + error(message: string): void +} + +// `var` is required here, +// otherwise the `blessing` property won't appear in `globalThis` type +declare var blessing: BlessingGlobals + +interface Window { + blessing: BlessingGlobals +}