Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(v3/lifecycle): Enhanced type for onErrorCaptured #12735

Merged
merged 1 commit into from Aug 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/v3/apiLifecycle.ts
Expand Up @@ -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')
Expand All @@ -51,3 +50,19 @@ export const onRenderTracked =
createLifeCycle<(e: DebuggerEvent) => any>('renderTracked')
export const onRenderTriggered =
createLifeCycle<(e: DebuggerEvent) => any>('renderTriggered')

export type ErrorCapturedHook<TError = unknown> = (
err: TError,
instance: any,
info: string
) => boolean | void

const injectErrorCapturedHook =
createLifeCycle<ErrorCapturedHook<any>>('errorCaptured')

export function onErrorCaptured<TError = Error>(
hook: ErrorCapturedHook<TError>,
target: any = currentInstance
) {
injectErrorCapturedHook(hook, target)
}