]> git.ipfire.org Git - thirdparty/moment.git/commit
Make moment's typings for parsing stricter and also allow them to accept union types.
authorSean Kelley <seansfkelley@gmail.com>
Sun, 24 Jul 2016 09:45:09 +0000 (11:45 +0200)
committerIskren Chernev <iskren.chernev@gmail.com>
Wed, 7 Sep 2016 08:37:57 +0000 (01:37 -0700)
commit0866ff94f3cf02f1a7b885daec2b4ad2e045301a
tree6b0db68cbd8995bc6935aa7156d2783a778e5c91
parentb5c51dd73ea64f2bd107f829b18ddbdeacd58da4
Make moment's typings for parsing stricter and also allow them to accept union types.

This commit was adapted from 1ec036686e70ad0d837ed2443684d54bca13af01 in DefinitelyTyped.
See https://github.com/DefinitelyTyped/DefinitelyTyped/pull/8765 for context. The original
body of the commit message follows.

These changes do two things.

1. Replace very lax typings like `any[]` with stricter, more-correct versions. In particular,
the ISO_8601 constant, while /technically/ a void function, is actually an opaque sentinel
that a consumer should not know anything about it. The function type was replaced with a
sentinel type using the principle of "brands" that can be seen in the Typescript compiler:
https://github.com/Microsoft/TypeScript/blob/413d9a639f933df7539070b236c1677de8302a93/src/compiler/types.ts#L9

2. Replace the many overloads of the parsing methods with a smaller representative set that
uses union types instead. Aside from succinctness, this allows callers to provide a union
type as the argument, as long as it matches, which was not possible before (Typescript does
not explode the union type to see if overloads cover all the possibilities).
moment.d.ts