[refactored] kwargs to come first when there's a shorthand overload

Authored by appsforartists on Oct 8 2017, 11:37 PM.


[refactored] kwargs to come first when there's a shorthand overload

TypeScript tries each signature in order. When one fails, it tries the next. As it says in the documentation:

it's customary to order overloads from most specific to least specific.

In cases where the shorthand argument has a specified value (e.g. number | Point2D), order shouldn't matter - both signatures are specific. However, in cases where the shorthand argument is generic (e.g. U | Observable<U>), TypeScript will incorrectly presume U is whatever the shape of kwargs is, and error accordingly when something tries to consume the emission.

By putting kwargs first, we're telling TypeScript "try to destructure this, and only use the shorthand if destructuring failed," which is the same strategy followed by our actual implementation: the shorthand is only attempted if destructuring failed.

In order to promote consistency and good practices, I've moved kwargs to the top of every overloaded operator, even in cases where order shouldn't matter.

Reviewers: O2 Material Motion, O3 Material JavaScript platform reviewers, Material Motion, vietanh

Reviewed By: Material Motion, vietanh

Tags: Material Motion

Differential Revision: http://codereview.cc/D3430