On Mon, Jun 29, 2015 at 5:56 PM, 'Bob Nystrom' via Dart Misc <
Post by 'Bob Nystrom' via Dart MiscPost by Kasper PeulenI 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()
<http://api.jquery.com/bind/> method from Dart. If all you had is union
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
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.
I would like that very much. We would probably still need union types, at
least in the static type system, to account for these types, but I think it
will cover enough use-cases that we won't need union type syntax.
We could even express the "number operator exceptions" of the type system
as:
int operator+(int a, int b);
double operator+(double a, num b);
double operator+(num a, double b);
And for Future<T>.sync:
Future.sync(T action());
Future.sync(Future<T> action());
And Future.catchError:
Future.catchError(errorHandler(error), [bool test(error)]);
Future.catchError(errorHandler(error, StackTrace stack), [bool
test(error)]);
/L
--
Lasse R.H. Nielsen - ***@google.com
'Faith without judgement merely degrades the spirit divine'
Google Denmark ApS - Frederiksborggade 20B, 1 sal - 1360 KÞbenhavn K
- Denmark - CVR nr. 28 86 69 84
--
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+***@dartlang.org.