@typescript-eslint/explicit-function-return-type
@typescript-eslint/eslint-plugin
No autofix
eslint.config.js
Require explicit return types on functions and class methods
// Should indicate that no value is returned (void)
function test() {
return;
}
// Should indicate that a number is returned
var fn = function () {
return 1;
};
// Should indicate that a string is returned
var arrowFn = () => 'test';
class Test {
// Should indicate that no value is returned (void)
method() {
return;
}
}// No return value should be expected (void)
function test(): void {
return;
}
// A return value of type number
var fn = function (): number {
return 1;
};
// A return value of type string
var arrowFn = (): string => 'test';
class Test {
// No return value should be expected (void)
method(): void {
return;
}
}Examples from the ESLint documentation.
Enforce a maximum number of parameters in function definitions
Enforce that class methods utilize this
Require or disallow initialization in variable declarations
Require destructuring from arrays and/or objects
Require a consistent member declaration order
@typescript-eslint/explicit-function-return-type
@typescript-eslint/eslint-plugin
typescript/explicit-function-return-type
typescript plugin · restriction
nursery/useExplicitReturnType
nursery · since 2.4.11
{
"rules": {
"typescript/explicit-function-return-type": "error"
}
}import tseslint from "typescript-eslint";
export default [
{
plugins: { "@typescript-eslint": tseslint.plugin },
rules: {
"@typescript-eslint/explicit-function-return-type": "error",
},
},
];{
"linter": {
"rules": {
"nursery": {
"useExplicitReturnType": "error"
}
}
}
}