Skip to main content

no-unnecessary-type-arguments

Disallow type arguments that are equal to the default.

🔧

Some problems reported by this rule are automatically fixable by the --fix ESLint command line option.

💭

This rule requires type information to run.

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: e.g. calling f<number>(...). This rule reports when an explicitly specified type argument is the default for that type parameter.

.eslintrc.cjs
module.exports = {
"rules": {
"@typescript-eslint/no-unnecessary-type-arguments": "error"
}
};
Try this rule in the playground ↗

Examples

function f<T = number>() {}
f<number>();
Open in Playground
function g<T = number, U = string>() {}
g<string, string>();
Open in Playground
class C<T = number> {}
new C<number>();

class D extends C<number> {}
Open in Playground
interface I<T = number> {}
class Impl implements I<number> {}
Open in Playground

Options

This rule is not configurable.

Resources