@typescript-eslint/no-unnecessary-type-arguments

Disallow a type argument that is the same as the default of its type parameter

fixableneeds types

Also called typescript-eslint/no-unnecessary-type-arguments, typescript/no-unnecessary-type-arguments

A type parameter can have a default, like <T = string>. Passing that same type yourself doesn't change anything.

Only the last type argument is checked, because you can't leave out the earlier ones while it's there.

--fix removes the type argument.

Configure#

Off by default. This rule needs types, so turning it on makes bun lint type check your code first.

bunfig.toml
[lint.rules]
"@typescript-eslint/no-unnecessary-type-arguments" = "error" # or "warn"

Examples#

example.ts3 problems
class Store<Value = string> {
  items: Value[] = [];
}

const labels: Store<string> = new Store<string>();

class TagStore extends Store<string> {}
example.tsNo problems
class Store<Value = string> {
  items: Value[] = [];
}

const labels: Store = new Store();
const counts = new Store<number>();

class TagStore extends Store {}

With several type parameters, the first argument stays if the last one differs from its default:

example.tsNo problems
interface Result<Data = unknown, Failure = Error> {
  data?: Data;
  failure?: Failure;
}

let result: Result<unknown, string>;