强制使用函数类型而不是带有签名的对象类型。
规则配置
// code-linter.json5
{
"rules": {
"@typescript-eslint/prefer-function-type": "error"
}
} 正例
export function foo(example: () => number): number {
return example();
}
// returns the function itself, not the `this` argument.
export type ReturnsSelf = (arg: string) => ReturnsSelf;
export interface Foo {
bar: string;
} 反例
interface GeneratedTypeLiteralInterface {
(): number;
}
export function foo(example: GeneratedTypeLiteralInterface): number {
return example();
}
export interface Foo {
(bar: string): this;
}