Skip to content

defaultParameterLast

Enforce default parameters to be last.

✅ This rule is included in the ts untyped preset.

Putting default parameters last allows function calls to omit optional tail arguments. When default parameters appear before required ones, callers must explicitly pass undefined to skip them.

This rule reports parameters with default values or optional markers (?) that appear before required parameters.

function greet(name = "World", greeting: string) {
console.log(`${greeting}, ${name}!`);
}
function calculate(a = 1, b: number, c = 2) {
return a + b + c;
}
const fn = (x = 0, y: number) => x + y;
function example(a?: number, b: number) {
return (a ?? 0) + b;
}

This rule is not configurable.

If your API design intentionally places default parameters before required ones for readability or documentation purposes, you may disable this rule. Some legacy APIs may also have established parameter orderings that cannot be changed without breaking changes.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.