We’re constantly talking on the Dart team about how to improve the language (like non-nullable types), and one of the features that has come up informally a few times is function overloading:

In some programming languages, function overloading or method overloading is the ability to create multiple methods of the same name with different implementations. Calls to an overloaded function will run a specific implementation of that function appropriate to the context of the call, allowing one function call to perform different tasks depending on context.

In short, this means you can write code like this (here’s a Java example):

A quick note: This is not an official stance of either Dart or Google, and also is not meant to be seen as a negative portrayal of TypeScript, but rather just a comparison of various benefits (and deficiencies) of both languages — for example TypeScript supports union types today and Dart does not.

We can’t do this (yet) in Dart, (or JavaScript, or TypeScript) but you can do:

An example of creating specialized messages to handle different argument types.

Of course, this isn’t very ergonomic. We could also omit the type definition entirely, and rely on a runtime check (in Dart) or use a union type (in TypeScript):

Note that in both cases I needed to do additional runtime type-checks to know how to dispatch something to the appropriate code block. I didn’t have to do that in Java.