@typescript-eslint/max-params
Enforce a maximum number of parameters in function definitions
Also called typescript-eslint/max-params, typescript/max-params
A call like createUser("Ada", "ada@example.com", true, false) says nothing about what each argument means, and you can swap two arguments of the same type without getting an error. Past three parameters, one object with named properties is easier to read and to extend.
It's the TypeScript version of max-params. It checks function types too, and it doesn't count a this: void parameter.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"@typescript-eslint/max-params" = "error" # or "warn"Every option, set to its default. The ones that are commented out are unset by default.
bunfig.toml
[lint.rules]
"@typescript-eslint/max-params" = ["error", {
max = 3,
# maximum = <number>,
countVoidThis = false,
}]Examples#
example.ts1 problem
function createUserFunction createUser has too many parameters (4). Maximum allowed is 3.(name: string, email: string, isAdmin: boolean, isActive: boolean) {
return { name, email, isAdmin, isActive };
}example.tsNo problems
interface NewUser {
name: string;
email: string;
isAdmin: boolean;
isActive: boolean;
}
function createUser(user: NewUser) {
return { ...user };
}
function move(this: void, x: number, y: number, z: number) {}Options#
| Option | Default | What it does |
|---|---|---|
max | 3 | The number of parameters a function can have. |
maximum | An older name for max. | |
countVoidThis | false | Count a this: void parameter like any other. |
example.tswith
{ "max": 1 }1 problemtype Add = (left: number, right: number) =>Function has too many parameters (2). Maximum allowed is 1. number;example.tswith
{ "countVoidThis": true }1 problemfunction moveFunction move has too many parameters (4). Maximum allowed is 3.(this: void, x: number, y: number, z: number) {}A this parameter of any other type is always counted:
example.ts1 problem
function moveFunction move has too many parameters (4). Maximum allowed is 3.(this: Window, x: number, y: number, z: number) {}