avoid-unnecessary-type-assertions
added in: 1.0.0 warning
Warns about unnecessary usage of is
and whereType
operators.
Example
Example 1: check is same type
class Example {
final myList = <int>[1, 2, 3];
void main() {
final result = myList is List<int>; // LINT
myList.whereType<int>();
}
}
Example 2: whereType method
main(){
['1', '2'].whereType<String?>(); // LINT
}
Example 3: patterns
class Animal {}
class HomeAnimal extends Animal {}
void main() {
final animal = Animal();
if (animal case HomeAnimal result) {}
if (animal case HomeAnimal()) {}
if (animal case Animal result) {} // LINT
if (animal case Animal()) {} // LINT
}