Skip to content

Latest commit

 

History

History
77 lines (50 loc) · 1.82 KB

no-return-void.md

File metadata and controls

77 lines (50 loc) · 1.82 KB

Disallow functions that don't return anything (functional/no-return-void)

💼🚫 This rule is enabled in the following configs: ☑️ lite, noStatements, ✅ recommended, 🔒 strict. This rule is disabled in the disableTypeChecked config.

💭 This rule requires type information.

Disallow functions that are declared as returning nothing.

Rule Details

In functional programming functions must return something, they cannot return nothing.

By default, this rule allows function to return undefined and null.

Note: For performance reasons, this rule does not check implicit return types. We recommend using the rule @typescript-eslint/explicit-function-return-type in conjunction with this rule.

❌ Incorrect

/* eslint functional/no-return-void: "error" */

function updateText(): void {}

✅ Correct

/* eslint functional/no-return-void: "error" */

function updateText(value: string): string {}

Options

This rule accepts an options object of the following type:

type Options = {
  allowNull: boolean;
  allowUndefined: boolean;
  ignoreInferredTypes: boolean;
};

Default Options

const defaults = {
  allowNull: true,
  allowUndefined: true,
  ignoreInferredTypes: false,
};

allowNull

If true allow returning null.

allowUndefined

If true allow returning undefined.

ignoreInferredTypes

If true ignore functions that don't explicitly specify a return type.