inferable_type_arguments_written_out
Reports type arguments of a collection literal or constructor call that the place would infer anyway. Delete them.
- Tier
- advisory
- Scope
- Dart
- Lowest preset
- strict
- Fix
- deletes the type arguments
What it reports
Section titled “What it reports”Type arguments of a collection literal or a constructor call, where the place gives exactly the static type of the expression. The violation is on the type arguments. Such places are:
- the initializer of a field or a top-level variable with a written type;
- the default value of a typed parameter;
- the value of an assignment;
- an argument whose parameter type has no type parameter in it;
- what a function or method with a written return type returns, unless it is
async, a generator or a function literal.
It does not report:
- a place of a wider type:
final Iterable<int> xs = <int>[]; - a variable without a written type, or a local variable: for a local variable the SDK lint
omit_local_variable_types(instrict) asks to drop its type instead; - an argument of a generic function or constructor whose type arguments are inferred from the argument.
The fix is not offered where a comment stands in the type arguments.
The type is written twice and has to be kept the same twice. Where the place’s type equals the expression’s type, inference gives the expression that type without the arguments.
Example
Section titled “Example”final Map<String, int> _prices = <String, int>{};final Map<String, int> _prices = {};Rule parameters
Section titled “Rule parameters”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. |
Suppressing it
Section titled “Suppressing it”Write why on the line directly above the suppression:
// Why it stays as written here.// ignore: inferable_type_arguments_written_out// ignore_for_file: assay/inferable_type_arguments_written_out silences it in a whole file, and // ignore: assay/inferable_type_arguments_written_out with the prefix works too. See Suppressions.