-
Notifications
You must be signed in to change notification settings - Fork 214
Optional Generics? #1387
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
I know this isn't your primary question, but concretely, this is because when designing Dart 2 inference, we chose to use subtype constraints instead of equality constraints. In other words, for your example we produce the constraints that |
To your primary question, this is a reasonable thing to think about doing - I don't think there'd be anything hard about it integrating it into inference. @munificent if we make |
An obvious line of thinking would be that when, say, However, that immediately calls for some syntax that allows us to specify other constraints, e.g., The approach where we can only specify an equality constraint may be a pragmatic sweet spot, but it might also be worth considering a feature where we can specify a broader set of constraints. |
+1. Note that my current proposal does not make |
what about default types? class Test<T = int, V = String> { ... class TestBase<T extends BaseType = BaseType> { ... |
That's a different feature: #283. |
Nit: The title feels like it is suggesting a different feature than what it actually asks. I do want to be able to write |
A problem with the current Generic implementation, is anytime you want to specify one type, you need to declare them all. This can lead to excessive typing and obfuscation of intent.
Sometimes I find I need to add specificity to just one of the types, it would be nice if this could be expressed as:
Instead of the current:
I've had to do this when there is some ambiguity to the inferred types, and you need to add a little bit of an extra hint to the compiler.
An example of such a case is like this:
If Thing was instead Thing<T1,T2,T3> this gets pretty annoying. The fact it falls to dynamic here is also annoying, but I guess that is a separate issue, or maybe a linter rule I'm missing.
The text was updated successfully, but these errors were encountered: