-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New annotations for enforcing types #60693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
SGTM, obviously. See: #60504, in particular Rather than saying which type you would stop supporting, which may not be directly usable, if fx an |
Great idea. What about a "union type"-like parameter? There could be a named constructor that accepts a list of types, I think. |
While this is useful for deprecations, I think it could expanded into a union type annotation. I could see it being useful for Uri.queryParameters because it's a Map<String, dynamic> which is really just To avoid having to specify it everywhere we can create a typedef and just apply the annotation to that. (I don't know if this would actually work, but it's a neat idea I think.) @UnionType([Map<String, String?>, Map<String, Iterable<String>])
typedef QueryParameters = Map<String, dynamic>; EDIT: Okay I just looked at the queryParameters type again and realized it's actually typed like |
I recently had a discussion on Discord about
ThemeData.cardTheme
that was accepting anObject
parameter in the current stable (because it originally acceptedCardTheme
), and with this issue and PR,CardThemeData
was created. In the current master, the oldCardTheme
can only be used as aWidget
(here is the migration guide as a reference).I'm not sure we have some annotation that could help users in this process. Something like "In a future version, we will stop supporting this type here" to be added to a parameter.
So we could do:
I could not find any similar issue, so I opened this one to gather more thoughts.
Something like this could also help (if the logic is reversed) if we want to do something like the above, but only accepting
CardTheme
andCardThemeData
(without union types), so we could say "We only accept these types here" in a way that the user can handle without running the code and failing or going through the docs to find all possibilities.For visibility @lrhn @srawlins @bwilkerson
The text was updated successfully, but these errors were encountered: