noVoidTypeReturn
Diagnostic Category: lint/correctness/noVoidTypeReturn
Since: v1.0.0
Disallow returning a value from a function with the return type ‘void’
‘void’ signals the absence of value. The returned value is likely to be ignored by the caller. Thus, returning a value when the return type of function is ‘void’, is undoubtedly an error.
Only returning without a value is allowed, as it’s a control flow statement.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.ts:3:9 lint/correctness/noVoidTypeReturn ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The function should not return a value because its return type is void.
1 │ class A {
2 │ f(): void {
> 3 │ return undefined;
│ ^^^^^^^^^^^^^^^^^
4 │ }
5 │ }
ℹ The function is here:
1 │ class A {
> 2 │ f(): void {
│ ^^^^^^^^^^^
> 3 │ return undefined;
> 4 │ }
│ ^
5 │ }
6 │
ℹ ‘void’ signals the absence of value. The returned value is likely to be ignored by the caller.
code-block.ts:3:9 lint/correctness/noVoidTypeReturn ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The function should not return a value because its return type is void.
1 │ const a = {
2 │ f(): void {
> 3 │ return undefined;
│ ^^^^^^^^^^^^^^^^^
4 │ }
5 │ }
ℹ The function is here:
1 │ const a = {
> 2 │ f(): void {
│ ^^^^^^^^^^^
> 3 │ return undefined;
> 4 │ }
│ ^
5 │ }
6 │
ℹ ‘void’ signals the absence of value. The returned value is likely to be ignored by the caller.
code-block.ts:2:5 lint/correctness/noVoidTypeReturn ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The function should not return a value because its return type is void.
1 │ function f(): void {
> 2 │ return undefined;
│ ^^^^^^^^^^^^^^^^^
3 │ }
4 │
ℹ The function is here:
> 1 │ function f(): void {
│ ^^^^^^^^^^^^^^^^^^^^
> 2 │ return undefined;
> 3 │ }
│ ^
4 │
ℹ ‘void’ signals the absence of value. The returned value is likely to be ignored by the caller.
code-block.ts:2:5 lint/correctness/noVoidTypeReturn ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The function should not return a value because its return type is void.
1 │ export default function(): void {
> 2 │ return undefined;
│ ^^^^^^^^^^^^^^^^^
3 │ }
4 │
ℹ The function is here:
> 1 │ export default function(): void {
│ ^^^^^^^^^^^^^^^^^^
> 2 │ return undefined;
> 3 │ }
│ ^
4 │
ℹ ‘void’ signals the absence of value. The returned value is likely to be ignored by the caller.
code-block.ts:2:5 lint/correctness/noVoidTypeReturn ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The function should not return a value because its return type is void.
1 │ const g = (): void => {
> 2 │ return undefined;
│ ^^^^^^^^^^^^^^^^^
3 │ };
4 │
ℹ The function is here:
> 1 │ const g = (): void => {
│ ^^^^^^^^^^^^^
> 2 │ return undefined;
> 3 │ };
│ ^
4 │
ℹ ‘void’ signals the absence of value. The returned value is likely to be ignored by the caller.
code-block.ts:2:5 lint/correctness/noVoidTypeReturn ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The function should not return a value because its return type is void.
1 │ const h = function(): void {
> 2 │ return undefined;
│ ^^^^^^^^^^^^^^^^^
3 │ };
4 │
ℹ The function is here:
> 1 │ const h = function(): void {
│ ^^^^^^^^^^^^^^^^^^
> 2 │ return undefined;
> 3 │ };
│ ^
4 │
ℹ ‘void’ signals the absence of value. The returned value is likely to be ignored by the caller.