How configure TypeScript ESLint to infer void when it's no return is provided

Viewed 386

I just turn on TypeScript ESLint to our company project.

I wish to get warns or errors when a function DOES returns a value but inffer void when no return type is provided.

for instance:

function sum(a: number, b: number) { // SHOULD ERROR
   return a+b;
}

should warn about there is no return type (it should be number), and:

function doSomething(value:number) { // SHOULD NOT WARN
   doesNotReturns();
}

Its correct, because there is no returning value.

How can i configure estlinrc to achieve this behavior?

1 Answers

First... in your rules add the new rule "@typescript-eslint/explicit-function-return-types". the rule has 3 options: off - no-error, 1-warnings, and 2- errors.

 "rules": {
    "@typescript-eslint/explicit-function-return-type": 1
 }
Related