Skip to content

unused_type_parameter

Reports a type parameter of a function or method that neither its signature nor its body uses. Remove it.

Tier
advisory
Scope
Dart
Lowest preset
strict
Fix
none

A type parameter of a top-level function, a local function or a method that neither the signature nor the body uses: void log<T>(Object message). The violation covers the type parameter’s name.

A use is a mention of the type parameter itself, found by what the name means, not its spelling: in the return type, a parameter’s type, another type parameter’s bound, or the body.

It does not report:

  • an override, with or without the annotation, which must keep the type parameters of the member it overrides;
  • a declaration without a body, abstract or external;
  • a type parameter named with underscores only.

A type parameter mentioned only in a documentation comment counts as used. A method of a base class whose overrides use the type parameter is reported on the base class: say so in a justified suppression.

A call log<int>(x) reads as if the type mattered, and it changes nothing. Most often the type parameter is left over from an earlier signature.

The rule is only in strict because it is about a clean signature, not a defect.

Violating
void log<T>(Object message) => print(message);
Corrected
void log(Object message) => print(message);

Set under the assay: key of the project’s root analysis_options.yaml.

Rule parameter Default Effect
enabled true false switches the rule off for the whole project.
exclude [] Path globs where the rule is silent.

Write why on the line directly above the suppression:

// Callers name the type for the reader; the log does not need it.
// ignore: assay/unused_type_parameter
void log<T>(Object message) => print(message);

// ignore_for_file: assay/unused_type_parameter silences it in a whole file, and // ignore: unused_type_parameter without the prefix works too. See Suppressions.