Urara-Blog/node_modules/.pnpm-store/v3/files/ca/721539cc5d40d9f053a9868402281d58a0700f3568a61c37aa3c50be727b11460f7ca0eb0155ff61a0ee3baf6c8dedf5678fc1136a1c219d908a30ef4e4ab3
2022-08-14 01:14:53 +08:00

68 lines
1.5 KiB
Text

---
description: 'Enforce default parameters to be last.'
---
> 🛑 This file is source code, not the primary documentation location! 🛑
>
> See **https://typescript-eslint.io/rules/default-param-last** for documentation.
## Rule Details
This rule extends the base [`eslint/default-param-last`](https://eslint.org/docs/rules/default-param-last) rule.
It adds support for optional parameters.
<!--tabs-->
### ❌ Incorrect
```ts
/* eslint @typescript-eslint/default-param-last: ["error"] */
function f(a = 0, b: number) {}
function f(a: number, b = 0, c: number) {}
function f(a: number, b?: number, c: number) {}
class Foo {
constructor(public a = 10, private b: number) {}
}
class Foo {
constructor(public a?: number, private b: number) {}
}
```
### ✅ Correct
```ts
/* eslint @typescript-eslint/default-param-last: ["error"] */
function f(a = 0) {}
function f(a: number, b = 0) {}
function f(a: number, b?: number) {}
function f(a: number, b?: number, c = 0) {}
function f(a: number, b = 0, c?: number) {}
class Foo {
constructor(public a, private b = 0) {}
}
class Foo {
constructor(public a, private b?: number) {}
}
```
## How to Use
```jsonc
{
// note you must disable the base rule as it can report incorrect errors
"default-param-last": "off",
"@typescript-eslint/default-param-last": ["error"]
}
```
## Options
See [`eslint/default-param-last` options](https://eslint.org/docs/rules/default-param-last#options).
<sup>
Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/default-param-last.md)
</sup>