persona-community-5/.pnpm-store/v3/files/45/99f1b2f7bae96a26e7891bd3924ab7e6359f82cdf693cb8676abd55289eed1bdacc54a5d2b73de35ff660d1716cc2a016d17906384f08f74e70f846ca0c6d1
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

86 lines
1.5 KiB
Plaintext

---
description: 'Disallow type arguments that are equal to the default.'
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
> 🛑 This file is source code, not the primary documentation location! 🛑
>
> See **https://typescript-eslint.io/rules/no-unnecessary-type-arguments** for documentation.
Type parameters in TypeScript may specify a default value.
For example:
```ts
function f<T = number>(/* ... */) {
// ...
}
```
It is redundant to provide an explicit type parameter equal to that default: e.g. calling `f<number>(...)`.
This rule reports when an explicitly specified type argument is the default for that type parameter.
## Examples
<Tabs>
<TabItem value="❌ Incorrect">
```ts
function f<T = number>() {}
f<number>();
```
```ts
function g<T = number, U = string>() {}
g<string, string>();
```
```ts
class C<T = number> {}
new C<number>();
class D extends C<number> {}
```
```ts
interface I<T = number> {}
class Impl implements I<number> {}
```
</TabItem>
<TabItem value="✅ Correct">
```ts
function f<T = number>() {}
f();
f<string>();
```
```ts
function g<T = number, U = string>() {}
g<string>();
g<number, number>();
```
```ts
class C<T = number> {}
new C();
new C<string>();
class D extends C {}
class D extends C<string> {}
```
```ts
interface I<T = number> {}
class Impl implements I<string> {}
```
</TabItem>
</Tabs>
## When Not To Use It
If you prefer explicitly specifying type parameters even when they are equal to the default, you can skip this rule.