unnecessary_type_check
Unnecessary type check; the result is always 'false'.
Unnecessary type check; the result is always 'true'.
Description
#The analyzer produces this diagnostic when the value of a type check (using either is
or is!
) is known at compile time.
Example
#The following code produces this diagnostic because the test a is Object?
is always true
:
bool f<T>(T a) => a is Object?;
Common fixes
#If the type check doesn't check what you intended to check, then change the test:
bool f<T>(T a) => a is Object;
If the type check does check what you intended to check, then replace the type check with its known value or completely remove it:
bool f<T>(T a) => true;
Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.