Typescript async function return type void vs Promise

Yes there’s a difference

void is a little like the opposite of any: the absence of having any type at all. You may commonly see this as the return type of functions that do not return a value

I guess Promise<void> doesn’t require explanation.


Now why the assignment in the question is allowed? Because target function (() => void) can be called in all (*almost) the same situations as the source function. Have a look at simplified example:

declare let voidFunc: () => void;
declare let promiseFunc: () => Promise<void>;

voidFunc = promiseFunc; // OK
promiseFunc = voidFunc; // Error: Type 'void' is not assignable to type 'Promise<void>'

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)