'errorHandling in Vue 3 with TypeScript
I'm working on migrating my Vue project to version 3.0.
I'm encountering an odd error when wanting to use the errorHandler function. Here is how I'm instantiating it in main.ts.
const app = createApp(App);
app.config.errorHandler = (err: unknown, instance: ComponentPublicInstance | null, info: string) => {
// handling the error
}
[...]
I've also added a definition inside a declaration file.
declare module '@vue/runtime-core' {
export interface ComponentCustomProperties {
$errorHandler: (err: unknown, instance: ComponentPublicInstance | null, info: string) => void;
}
}
Every time, the function is being called I get this error:
TypeError: this.$errorHandler is not a function
I don't understand what I'm doing wrong. I'm doing the same thing for other global variables instantiated on app.config.globalProperties and it works properly.
Anybody has encountered the same issue?
UPDATE
Is it a good practice to assign the errorHandler to a global property?
app.config.globalProperties.errorHandler = app.config.errorHandler;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
