proposal: type_local_variable_instead_of_casting
#58903
Labels
analyzer-linter
Issues with the analyzer's support for the linter package
area-analyzer
Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
linter-lint-proposal
linter-status-pending
P3
A lower priority bug or feature request
type-enhancement
A request for a change that isn't a bug
type_local_variable_instead_of_casting
Please respond with a better name if you have one.
prefer_type_annotation_over_cast
?Description
This rule encourages one to "cast" (generally upcast) an expression in a new local variable via the variable's declaration rather than an as-expression. I hope that's crystal clear :)
Details
Sometimes an expression is upcast via
as
, such as:Errors would arise if either cast were removed. However, we could make the code more idiomatic by casting with the variable's declaration (side-stepping inference):
This arises from lots of discussion in #48984, and examples in #44411, #49269, and #49550.
Kind
Style.
Discussion
See discussion at #48984.
Discussion checklist
The text was updated successfully, but these errors were encountered: