Skip to content
← Back to rules

typescript/no-unnecessary-type-parameters Suspicious

💭 This rule requires type information.
💡 A suggestion is available for this rule.

What it does ​

Disallow type parameters that are declared but not meaningfully used.

Why is this bad? ​

Unnecessary type parameters make signatures noisier and harder to understand, and they often hide opportunities to simplify APIs.

Examples ​

Examples of incorrect code for this rule:

ts
function parseYAML<T>(input: string): T {
  return input as any as T;
}

Examples of correct code for this rule:

ts
function parseYAML(input: string): unknown {
  return input;
}

function identity<T>(value: T): T {
  return value;
}

How to use ​

To enable this rule using the config file or in the CLI, you can use:

json
{
  "options": {
    "typeAware": true
  },
  "rules": {
    "typescript/no-unnecessary-type-parameters": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  options: { typeAware: true },
  rules: {
    "typescript/no-unnecessary-type-parameters": "error",
  },
});
bash
oxlint --type-aware --deny typescript/no-unnecessary-type-parameters

Version ​

This rule was added in v1.49.0.

References ​