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.
Examples
Section titled “Examples”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;}function greet(greeting: string, name = "World") { console.log(`${greeting}, ${name}!`);}function calculate(b: number, a = 1, c = 2) { return a + b + c;}const fn = (y: number, x = 0) => x + y;function example(a = 1, ...rest: number[]) { return rest.reduce((sum, value) => sum + value, a);}Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.