Skip to main content

no_raw_types

Learn about the no_raw_types linter rule.

Unreleased
Released in Dart 3.13

Avoid raw types.

Details

#

DON'T use raw types.

A raw type is a type annotation for a generic type which omits type arguments. Developers may mistakenly believe that the type arguments are inferred, but in fact each type parameter's bound is used, which can lead to lost type information.

BAD:

dart
List list = [1, 2, 3];

GOOD:

dart
List<int> list = [1, 2, 3];

Enable

#

To enable the no_raw_types rule, add no_raw_types under linter > rules in your analysis_options.yaml file:

analysis_options.yaml
yaml
linter:
  rules:
    - no_raw_types

If you're instead using the YAML map syntax to configure linter rules, add no_raw_types: true under linter > rules:

analysis_options.yaml
yaml
linter:
  rules:
    no_raw_types: true