no-unnecessary-type-arguments
Disallows type arguments that are equal to the default.
Warns if an explicitly specified type argument is the default for that type parameter.
Attributes
- Included in configs
- ✅ Recommended
- 🔒 Strict
- Fixable
- 🔧 Automated Fixer
- 🛠 Suggestion Fixer
- 💭 Requires type information
Rule Details
Type parameters in TypeScript may specify a default value. For example:
function f<T = number>() {}
It is redundant to provide an explicit type parameter equal to that default.
Examples of code for this rule:
- ❌ Incorrect
- ✅ Correct
function f<T = number>() {}
f<number>();
function g<T = number, U = string>() {}
g<string, string>();
class C<T = number> {}
function h(c: C<number>) {}
new C<number>();
class D extends C<number> {}
interface I<T = number> {}
class Impl implements I<number> {}
function f<T = number>() {}
f<string>();
function g<T = number, U = string>() {}
g<number, number>();
class C<T = number> {}
new C<string>();
class D extends C<string> {}
interface I<T = number> {}
class Impl implements I<string> {}
Options
// .eslintrc.json
{
"rules": {
"@typescript-eslint/no-unnecessary-type-arguments": "warn"
}
}
This rule is not configurable.
Related To
- TSLint: use-default-type-parameter