In typescript, how to define type of async function

Found this searching how to declare a “typedef” for an async arrow function.

It works if you just declare the return type of the function to be a Promise:

interface SearchFn {
    (subString: string): Promise<boolean>;
}

or as a type declaration:

type SearchFn = (subString: string) => Promise<boolean>;

Microsoft’s TS Linter will recommend this second syntax.

Leave a Comment

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