persona-community-5/.pnpm-store/v3/files/58/45ce375390e4ff4b900da64b1762db4d98aafb8b11d6121e445caa90b4323bc087e0e2c3ba44383d008d88bcd6be06aa6a99b278862fcbb8aed426a7862389
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

53 lines
1.3 KiB
Plaintext

---
description: 'Require `return` statements to either always or never specify values.'
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
> 🛑 This file is source code, not the primary documentation location! 🛑
>
> See **https://typescript-eslint.io/rules/consistent-return** for documentation.
This rule extends the base [`eslint/consistent-return`](https://eslint.org/docs/rules/consistent-return) rule.
This version adds support for functions that return `void` or `Promise<void>`.
:::danger warning
If possible, it is recommended to use tsconfig's `noImplicitReturns` option rather than this rule. `noImplicitReturns` is powered by TS's type information and control-flow analysis so it has better coverage than this rule.
:::
<Tabs>
<TabItem value="❌ Incorrect">
```ts
function foo(): undefined {}
function bar(flag: boolean): undefined {
if (flag) return foo();
return;
}
async function baz(flag: boolean): Promise<undefined> {
if (flag) return;
return foo();
}
```
</TabItem>
<TabItem value="✅ Correct">
```ts
function foo(): void {}
function bar(flag: boolean): void {
if (flag) return foo();
return;
}
async function baz(flag: boolean): Promise<void | number> {
if (flag) return 42;
return;
}
```
</TabItem>
</Tabs>