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

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

Details

Summary

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.

Diff Detail

Repository
R13 material-motion/material-motion-js
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
appsforartists created this revision.Oct 8 2017, 11:42 PM
Restricted Application added a reviewer: O2: Material Motion. · View Herald TranscriptOct 8 2017, 11:42 PM
Restricted Application added a project: Material Motion. · View Herald Transcript
Restricted Application added a reviewer: O3: Material JavaScript platform reviewers. · View Herald Transcript
Restricted Application added a reviewer: Material Motion. · View Herald Transcript
Restricted Application completed building Restricted Buildable.Oct 8 2017, 11:45 PM
vietanh accepted this revision.Oct 11 2017, 12:21 AM
This revision is now accepted and ready to land.Oct 11 2017, 12:21 AM
appsforartists edited the summary of this revision. (Show Details)Oct 11 2017, 1:13 AM
This revision was automatically updated to reflect the committed changes.