-
Notifications
You must be signed in to change notification settings - Fork 213
Nested typedefs #2952
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
Added Area-Language, Triaged labels. |
Our need for typedefs stems from issues around the function type syntax. We can't support anonymous function types very well, which leads to these problems. One can work around them with generic typedefs though. typedef void Callback<S> (S s);
class Foo<T> {
Callback<T> _callback;
Foo(this._callback);
...
} |
Presumably this is still an issue, but not actively being worked on. :) I came across this looking for an issue on how to make a typedef for a specialized generic, like e.g. https://dartpad.dartlang.org/31438e9a6ac9d097c3b6642f66abf935 |
I'm not sure, but issue dart-lang/sdk#27527 might be related to your need. |
@eseidelGoogle Yes, currently |
This is still an issue, but is a different one from what you describe. This one is about allowing |
I still see no reason to prohibit local typedefs, but the new function type syntax allows you to write function types directly so you don't need a typedef to write a function type. |
I find inline function types make code hard to read. I prefer typedefs. |
The other use case for local typedefs that we have discussed involves type variables: class Thing<A, B, C> {
typedef Factory = Thing<A, B, C> Function({A a, B b, List<C> cs = []});
// `Factory` used many times.
} A global It's definitely possible to argue that this abbreviation is a good thing or that it is a bad thing, but if we decide to support allowing all types (not just function types) on the right hand side of a global |
Completed via #65 |
Got it, thanks |
Related issue for nested classes: #336 |
Nested typedefs are slightly simpler than nested classes because typedefs won't introduce a new namespace level. |
... and with generalized type aliases, the above comment is no longer correct. We allow accessing static members through a type alias for a class type (as long as the type alias precisely that class type), abstract final class _NameSpace2 {
static final int x = 42;
}
abstract final class ns1 {
static final int x = 37;
typedef ns2 = _NameSpace2;
}
void main() {
print(ns1.x);
print(ns1.ns2.x); // Works?
} On way to avoid that is to make "local" type alias declaration not become part of the external scope. Another approach would be to allow declarations to nest. You'd have to write |
Currently typedef can only appear at the toplevel. If I have a class that I want to allow a user supplied callback and maintain type checking, there currently is no way:
The text was updated successfully, but these errors were encountered: