Linter · Rules
@typescript-eslint/no-unnecessary-type-arguments
Disallow a type argument that is the same as the default of its type parameter
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
Reported:
class Store<Value = string> {
items: Value[] = [];
}
const labels: Store<string> = new Store<string>();
class TagStore extends Store<string> {}
Not reported:
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:
interface Result<Data = unknown, Failure = Error> {
data?: Data;
failure?: Failure;
}
let result: Result<unknown, string>;