Skip to main content

avoid_unnecessary_type_assertions

Warns about unnecessary usage of is and whereType operators.

Example:

BAD:

final testList = [1.0, 2.0, 3.0];
final result = testList is List<double>; // LINT
final negativeResult = testList is! List<double>; // LINT
testList.whereType<double>(); // LINT

final double d = 2.0;
final casted = d is double; // LINT

GOOD:

final dynamicList = <dynamic>[1.0, 2.0];
dynamicList.whereType<double>();

final double? nullableD = 2.0;
// casting `Type? is Type` is allowed
final castedD = nullableD is double;