From bba6b3d6b4e3e26d28abbf20e74ec2f3e64f1a92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E8=A7=81=E6=9C=88?= <61452855+nooooooom@users.noreply.github.com> Date: Thu, 18 Aug 2022 16:20:27 +0800 Subject: [PATCH] feat(types): enhance type for onErrorCaptured (#12735) --- src/v3/apiLifecycle.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/v3/apiLifecycle.ts b/src/v3/apiLifecycle.ts index dc47bc465..31e054292 100644 --- a/src/v3/apiLifecycle.ts +++ b/src/v3/apiLifecycle.ts @@ -42,7 +42,6 @@ export const onBeforeUpdate = createLifeCycle('beforeUpdate') export const onUpdated = createLifeCycle('updated') export const onBeforeUnmount = createLifeCycle('beforeDestroy') export const onUnmounted = createLifeCycle('destroyed') -export const onErrorCaptured = createLifeCycle('errorCaptured') export const onActivated = createLifeCycle('activated') export const onDeactivated = createLifeCycle('deactivated') export const onServerPrefetch = createLifeCycle('serverPrefetch') @@ -51,3 +50,19 @@ export const onRenderTracked = createLifeCycle<(e: DebuggerEvent) => any>('renderTracked') export const onRenderTriggered = createLifeCycle<(e: DebuggerEvent) => any>('renderTriggered') + +export type ErrorCapturedHook = ( + err: TError, + instance: any, + info: string +) => boolean | void + +const injectErrorCapturedHook = + createLifeCycle>('errorCaptured') + +export function onErrorCaptured( + hook: ErrorCapturedHook, + target: any = currentInstance +) { + injectErrorCapturedHook(hook, target) +}