Any updates on union types? Last time they were mentioned was in http://news.dartlang.org/2015/01/dart-language-evolution-discussed-in.html and I haven't seen a DEP around them. This still something that could be added?
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
Thanks for the update Gilad. Thought it was more of a priority as typescript and closure compiler have that functionality. Is anyone planning on taking a stab at a dep for it? Been thinking about getting involved in the dep process.
--
As I said, dart2js interop was the motivation; it may be that DDC just learns to read .ts header files or something. Hence it is less of a priority than it was.
I don't understand why this would make it less a priority. If you are doing interop in dart with union types, then I would think that it is also desriable that the analyser understand the object is an union type not just the compiler.
Since the DDC folks are investigating supporting TypeScript definition files anyway, we may have to allow overloads like this. In that case, union types may not add much additional value. (Note that TypeScript has had overloading since they first launched but is only just now getting around to adding union types.)
void doSomething(dynamic value) {
if (value is String) {
..
} else if (value is List<String>) {
..
} else {
throw new ArgumentError('value is not a String or List of String');
}
}
void doSomething(String|List<String> value) {
if (value is String) {
} else {
// I'm for sure a List<String>
..
}
}
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
String or List<String>,
removing the second check for List<String> doesn't seem so safe.You can guarantee it with the "non-nullable types by default" proposal which (given those in favor) might be implemented.
--
On Sun, Jun 28, 2015 at 4:38 PM, Kasper Peulen <kasper...@gmail.com> wrote:I don't understand why this would make it less a priority. If you are doing interop in dart with union types, then I would think that it is also desriable that the analyser understand the object is an union type not just the compiler.The main motivation for union types is better JS interop. But, in many cases, you can get a much tighter type by using something like TypeScript's interface overloading feature than you would get using union types.For example, say you want to call jQuery's bind() method from Dart. If all you had is union types, its type is something like:bind(String | Map eventTypeOrEvents, [Map | Function | bool eventDataOrHandlerOrPreventBubble, bool | Function, handlerOrPreventBubble]);The types aren't clear. The parameter names aren't clear, and it allows a bunch of things that are not in fact valid, like passing booleans for both of the last two parameters. If you have overloading, it's:bind(String eventType, Function handler);bind(String eventType, Map eventData, Function handler);bind(String eventType, [Map eventData, bool preventBubble]);bind(Map events);That's much clearer and more explicit.