Require any function or method that returns a Promise to be marked async.
// code-linter.json5
{
"rules": {
"@typescript-eslint/promise-function-async": "error"
}
} export const arrowFunctionReturnsPromise = async () => Promise.resolve('value');
export async function functionReturnsPromise() {
return Promise.resolve('value');
}
// An explicit return type that is not Promise means this function cannot be made async, so it is ignored by the rule
export function functionReturnsUnionWithPromiseExplicitly(
p: boolean
): string | Promise<string> {
return p ? 'value' : Promise.resolve('value');
}
export async function functionReturnsUnionWithPromiseImplicitly(p: boolean) {
return p ? 'value' : Promise.resolve('value');
} export const arrowFunctionReturnsPromise = () => Promise.resolve('value');
export function functionReturnsPromise() {
return Promise.resolve('value');
}
export function functionReturnsUnionWithPromiseImplicitly(p: boolean) {
return p ? 'value' : Promise.resolve('value');
} plugin:@typescript-eslint/all
For details about how to configure Code Linter check rules, see Code Linter.