Closed dark-chocolate closed 4 years ago
Thanks! All makes sense to me at least ;)
pedantic
isn't the right place to discuss, though; this package is just about publishing the analyzer configuration we use internally at google3.
I think the right place would be either the SDK or the linter
https://github.com/dart-lang/sdk/issues/new https://github.com/dart-lang/linter
--would you mind refiling at one of those, please? :)
@davidmorgan Sure sir, I am opening it in linter.
I asked similar question on this comment, but the team didn't really respond quite well. I am thus creating a new issue.
You can either use
as
or type annotation to upcast or downcast things, let's take this example, where I have aSizedBox
and I want to upcast to aWidget
, so that I don't want to allow users to usewidth
property on it, in this example I am usingas
to upcast, but this gives me a warning:(Whenever I am writing
bad
in comment, that means it is undesired behavior, andgood
for desired one)Now if I take warning into consideration and modify my code to silence pedantic, I can do:
But this allows me to access
width
which I don't want.Second solution is to use type annotation like:
So you can clearly see if I use
as
, I get myself in trouble and can only do limited things but if I use type annotation, I can do things the way I want. Let's take one more example into consideration (thanks to @eernstg )As you can see if I am again comparing
as
with type annotation, the latter has advantages almost everywhere.