Just do IT

思うは招く

TypeScript async function の型をどう書くか

async関数のreturn typeにvoidを定義した。

const someFunc = async (): void => {
    await someMethod()
}

TypeScriptに叱られる。

Type 'void' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value

こう書く。

const someFunc = async (): Promise<void> => {
    await someMethod()
}

stringやオブジェクトを返したいなら。

const someFunc = async (): Promise<string> => {
    await someMethod()
}


type Props = { ~ }
const someFunc = async (): Promise<Props> => {
    await someMethod()
}