# @typescript-eslint/no-unnecessary-type-parameters

> Disallow a type parameter that is used only once in a signature

A type parameter connects two things, like an argument and the return type, or one argument and another. If it appears only once, it doesn't connect anything. Replace it with its constraint, or with `unknown`, and the signature means the same thing.

A type parameter that appears only as the return type is worse. The caller picks any type and the compiler believes it, which is a type assertion in disguise.

The rule checks functions, methods and classes. Only the signature counts, so uses inside a function body are ignored.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

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

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

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 3} */}
```ts
function log<Message>(message: Message): void {
  console.log(message);
}

function size<Item extends { length: number }>(item: Item): number {
  return item.length;
}

function load<Data>(key: string): Data {
  return JSON.parse(localStorage.getItem(key) ?? "null");
}
```

Not reported:

{/* good */}
```ts
function log(message: unknown): void {
  console.log(message);
}

function size(item: { length: number }): number {
  return item.length;
}

function load(key: string): unknown {
  return JSON.parse(localStorage.getItem(key) ?? "null");
}
```

Here each type parameter ties two places together:

{/* good */}
```ts
function first<Item>(items: Item[]): Item | undefined {
  return items[0];
}

function pick<Source, Key extends keyof Source>(source: Source, key: Key) {
  return source[key];
}

class Box<Value> {
  constructor(private value: Value) {}

  get(): Value {
    return this.value;
  }
}
```
