Require explicit return and argument types on exported functions' and classes' public class methods.
This rule applies only to .ts files.
// code-linter.json5
{
"rules": {
"@typescript-eslint/explicit-module-boundary-types": "error"
}
} // A function with no return value (void)
export function test1(): void {
return;
}
// A return value of type string
export const arrowFn1 = (): string => 'test';
// All arguments should be typed
export const arrowFn2 = (arg: string): string => `test ${arg}`;
export class Test {
// A class method with no return value (void)
public method(): void {
return;
}
}
// The function does not apply because it is not an exported function.
function test2() {
return;
}
test2(); // Should indicate that no value is returned (void)
export function test() {
return;
}
// Should indicate that a string is returned
export const arrowFn1 = () => 'test';
// All arguments should be typed
export const arrowFn2 = (arg): string => `test ${arg}`;
export const arrowFn3 = (arg: any): string => `test ${arg}`;
export class Test {
// Should indicate that no value is returned (void)
public method() {
return;
}
} plugin:@typescript-eslint/recommended plugin:@typescript-eslint/all
For details about how to configure Code Linter check rules, see Code Linter.