Skip to content

new lint: "Avoid unnecessary type annotations" #58375

Open
@pq

Description

@pq

Avoid type explicit type annotations when they can be inferred.

From the style guide:

If an invocation’s type argument list is correctly inferred with the types you want, then omit the types and let Dart do the work for you.

GOOD:

var strings = ['foo', 'bar', 'baz'];

var fakeSimStore = FakeStore(Sim());

var stars = Row(
  mainAxisSize: MainAxisSize.min,
  children: [
    Icon(Icons.star, color: Colors.green[500]),
    Icon(Icons.star, color: Colors.black),
  ],
);

BAD:

var strings = <String>['foo', 'bar', 'baz'];

var fakeSimStore = FakeStore<Sim>(Sim());

var stars = Row(
  mainAxisSize: MainAxisSize.min,
  children: <Widget>[
    Icon(Icons.star, color: Colors.green[500]),
    Icon(Icons.star, color: Colors.black),
  ],
);

/cc @jefflim-google

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.customer-google3devexp-linterIssues with the analyzer's support for the linter packagelinter-lint-requesttype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions