Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] More complete type definitions for strict formatless parsing #4611 #5574

Merged
merged 2 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 17 additions & 2 deletions moment.d.ts
Expand Up @@ -4,13 +4,13 @@
*/
declare function moment(inp?: moment.MomentInput, strict?: boolean): moment.Moment;
/**
* @param strict Strict parsing requires that the format and input match exactly, including delimeters.
* @param strict Strict parsing requires that the format and input match exactly, including delimiters.
* Strict parsing is frequently the best parsing option. For more information about choosing strict vs
* forgiving parsing, see the [parsing guide](https://momentjs.com/guides/#/parsing/).
*/
declare function moment(inp?: moment.MomentInput, format?: moment.MomentFormatSpecification, strict?: boolean): moment.Moment;
/**
* @param strict Strict parsing requires that the format and input match exactly, including delimeters.
* @param strict Strict parsing requires that the format and input match exactly, including delimiters.
* Strict parsing is frequently the best parsing option. For more information about choosing strict vs
* forgiving parsing, see the [parsing guide](https://momentjs.com/guides/#/parsing/).
*/
Expand Down Expand Up @@ -663,7 +663,22 @@ declare namespace moment {
export var fn: Moment;

// NOTE(constructor): Same as moment constructor
/**
* @param strict Strict parsing disables the deprecated fallback to the native Date constructor when
* parsing a string.
*/
export function utc(inp?: MomentInput, strict?: boolean): Moment;
/**
* @param strict Strict parsing requires that the format and input match exactly, including delimiters.
* Strict parsing is frequently the best parsing option. For more information about choosing strict vs
* forgiving parsing, see the [parsing guide](https://momentjs.com/guides/#/parsing/).
*/
export function utc(inp?: MomentInput, format?: MomentFormatSpecification, strict?: boolean): Moment;
/**
* @param strict Strict parsing requires that the format and input match exactly, including delimiters.
* Strict parsing is frequently the best parsing option. For more information about choosing strict vs
* forgiving parsing, see the [parsing guide](https://momentjs.com/guides/#/parsing/).
*/
export function utc(inp?: MomentInput, format?: MomentFormatSpecification, language?: string, strict?: boolean): Moment;

export function unix(timestamp: number): Moment;
Expand Down
2 changes: 2 additions & 0 deletions ts3.1-typing-tests/moment-tests.ts
Expand Up @@ -23,6 +23,8 @@ var day10 = moment([2010, 6, 10]);
var array = [2010, 1, 14, 15, 25, 50, 125];
var day11 = moment(Date.UTC.apply({}, array));
var day12 = moment.unix(1318781876);
var day13 = moment("/Date(1198908717056-0700)/", true);
var day14 = moment("foobazbar", 'L', true);

moment(null);
moment(undefined);
Expand Down
30 changes: 30 additions & 0 deletions ts3.1-typings/moment.d.ts
@@ -1,4 +1,19 @@
/**
* @param strict Strict parsing disables the deprecated fallback to the native Date constructor when
* parsing a string.
*/
declare function moment(inp?: moment.MomentInput, strict?: boolean): moment.Moment;
/**
* @param strict Strict parsing requires that the format and input match exactly, including delimiters.
* Strict parsing is frequently the best parsing option. For more information about choosing strict vs
* forgiving parsing, see the [parsing guide](https://momentjs.com/guides/#/parsing/).
*/
declare function moment(inp?: moment.MomentInput, format?: moment.MomentFormatSpecification, strict?: boolean): moment.Moment;
/**
* @param strict Strict parsing requires that the format and input match exactly, including delimiters.
* Strict parsing is frequently the best parsing option. For more information about choosing strict vs
* forgiving parsing, see the [parsing guide](https://momentjs.com/guides/#/parsing/).
*/
declare function moment(inp?: moment.MomentInput, format?: moment.MomentFormatSpecification, language?: string, strict?: boolean): moment.Moment;

declare namespace moment {
Expand Down Expand Up @@ -636,7 +651,22 @@ declare namespace moment {
export var fn: Moment;

// NOTE(constructor): Same as moment constructor
/**
* @param strict Strict parsing disables the deprecated fallback to the native Date constructor when
* parsing a string.
*/
export function utc(inp?: MomentInput, strict?: boolean): Moment;
/**
* @param strict Strict parsing requires that the format and input match exactly, including delimiters.
* Strict parsing is frequently the best parsing option. For more information about choosing strict vs
* forgiving parsing, see the [parsing guide](https://momentjs.com/guides/#/parsing/).
*/
export function utc(inp?: MomentInput, format?: MomentFormatSpecification, strict?: boolean): Moment;
/**
* @param strict Strict parsing requires that the format and input match exactly, including delimiters.
* Strict parsing is frequently the best parsing option. For more information about choosing strict vs
* forgiving parsing, see the [parsing guide](https://momentjs.com/guides/#/parsing/).
*/
export function utc(inp?: MomentInput, format?: MomentFormatSpecification, language?: string, strict?: boolean): Moment;

export function unix(timestamp: number): Moment;
Expand Down