From c8e501875850923e1c5fa103c138c36a867aab51 Mon Sep 17 00:00:00 2001 From: chris-zhu <1633711653@qq.com> Date: Mon, 18 Apr 2022 17:24:27 +0800 Subject: [PATCH 1/3] chore(docs): update hmr hot type --- docs/guide/api-hmr.md | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/docs/guide/api-hmr.md b/docs/guide/api-hmr.md index 46eabab04e8868..062a4c73817e56 100644 --- a/docs/guide/api-hmr.md +++ b/docs/guide/api-hmr.md @@ -10,21 +10,31 @@ Vite exposes its manual HMR API via the special `import.meta.hot` object: ```ts interface ImportMeta { - readonly hot?: { - readonly data: any + readonly hot?: ViteHotContext +} + +interface ViteHotContext { + readonly data: any + + accept(): void + accept(cb: (mod: any) => void): void + accept(dep: string, cb: (mod: any) => void): void + accept(deps: readonly string[], cb: (mods: any[]) => void): void - accept(): void - accept(cb: (mod: any) => void): void - accept(dep: string, cb: (mod: any) => void): void - accept(deps: string[], cb: (mods: any[]) => void): void + /** + * @deprecated + */ + acceptDeps(): never - prune(cb: () => void): void - dispose(cb: (data: any) => void): void - decline(): void - invalidate(): void + dispose(cb: (data: any) => void): void + decline(): void + invalidate(): void - on(event: string, cb: (...args: any[]) => void): void - } + on( + event: T, + cb: (payload: InferCustomEventPayload) => void + ): void + send(event: T, data?: InferCustomEventPayload): void } ``` From a17d903973bad5cddad4d25865bc198a0c0ba957 Mon Sep 17 00:00:00 2001 From: chris-zhu <1633711653@qq.com> Date: Tue, 19 Apr 2022 13:57:18 +0800 Subject: [PATCH 2/3] chore: docs remove deprecated fn --- docs/guide/api-hmr.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/docs/guide/api-hmr.md b/docs/guide/api-hmr.md index 062a4c73817e56..84d802899aef81 100644 --- a/docs/guide/api-hmr.md +++ b/docs/guide/api-hmr.md @@ -21,11 +21,6 @@ interface ViteHotContext { accept(dep: string, cb: (mod: any) => void): void accept(deps: readonly string[], cb: (mods: any[]) => void): void - /** - * @deprecated - */ - acceptDeps(): never - dispose(cb: (data: any) => void): void decline(): void invalidate(): void From e2f4c38de3c639a458d35c4d4e0f6d2d9a364426 Mon Sep 17 00:00:00 2001 From: chris-zhu <1633711653@qq.com> Date: Thu, 21 Apr 2022 14:44:36 +0800 Subject: [PATCH 3/3] chore: add `InferCustomEventPayload` coment --- docs/guide/api-hmr.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/guide/api-hmr.md b/docs/guide/api-hmr.md index 84d802899aef81..1cba492e6613c1 100644 --- a/docs/guide/api-hmr.md +++ b/docs/guide/api-hmr.md @@ -25,6 +25,7 @@ interface ViteHotContext { decline(): void invalidate(): void + // `InferCustomEventPayload` provides types for built-in Vite events on( event: T, cb: (payload: InferCustomEventPayload) => void