Skip to content

vue lifecycle hooks return void  #773

@Anubarak

Description

@Anubarak

My latest PHPStorm version complains because in your index.d.ts is the following code

declare const onBeforeMount: (callback: Function) => void;
declare const onMounted: (callback: Function) => void;
declare const onBeforeUpdate: (callback: Function) => void;
declare const onUpdated: (callback: Function) => void;
declare const onBeforeUnmount: (callback: Function) => void;
declare const onUnmounted: (callback: Function) => void;
declare const onErrorCaptured: (callback: Function) => void;
declare const onActivated: (callback: Function) => void;
declare const onDeactivated: (callback: Function) => void;
declare const onServerPrefetch: (callback: Function) => void;

So my IDE thinks

// unMounted is void
const unMounted = onBeforeUnmount(() => {
    // do something
});

Is there a way without using Typescript or ignoring the error via IDE settings to fix that? (I know it's not a real error but it looks ugly and I don't just want to surpass all IDE warnings)

image

When I take a look at the Vue 3 implementation they indeed return something

export declare const onBeforeMount: (hook: () => any, target?: ComponentInternalInstance | null) => false | Function | undefined;
export declare const onBeforeUnmount: (hook: () => any, target?: ComponentInternalInstance | null) => false | Function | undefined;
export declare const onBeforeUpdate: (hook: () => any, target?: ComponentInternalInstance | null) => false | Function | undefined;

Metadata

Metadata

Assignees

No one assigned

    Labels

    misalignmentMisalign with the latest RFC

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions