Skip to content

Commit

Permalink
[bugfix] Update the type definition of the humanize() API, fix compil…
Browse files Browse the repository at this point in the history
…ation error (#5525)
  • Loading branch information
Alanscut committed May 18, 2020
1 parent de98cc4 commit 2259e43
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
23 changes: 11 additions & 12 deletions moment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,23 +178,22 @@ declare namespace moment {
milliseconds: number;
}

interface HumanizeOptions {
withSuffix?: boolean;
thresholds?: {
ss?: number;
s?: number;
m?: number;
h?: number;
d?: number;
w?: number | void;
M?: number;
};
interface argThresholdOpts {
ss?: number;
s?: number;
m?: number;
h?: number;
d?: number;
w?: number | void;
M?: number;
}

interface Duration {
clone(): Duration;

humanize(withSuffixOrOptions?: boolean | HumanizeOptions): string;
humanize(argWithSuffix?: boolean, argThresholds?: argThresholdOpts): string;

humanize(argThresholds?: argThresholdOpts): string;

abs(): Duration;

Expand Down
12 changes: 12 additions & 0 deletions ts3.1-typing-tests/moment-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,15 @@ moment(1316116057189).fromNow();
moment.localeData('en');
var globalLang = moment();
var localLang = moment();
var thresholds = {
ss: 44,
s: 45,
m: 45,
h: 22,
d: 26,
w: 2,
M: 11,
};
localLang.localeData();
localLang.format('LLLL');
globalLang.format('LLLL');
Expand Down Expand Up @@ -264,6 +273,9 @@ moment.duration({
});
moment.duration(1, "minute").clone();
moment.duration(1, "minutes").humanize();
moment.duration(1, "minutes").humanize(true);
moment.duration(1, "minutes").humanize(thresholds);
moment.duration(1, "minutes").humanize(true, thresholds);
moment.duration(500).milliseconds();
moment.duration(500).asMilliseconds();
moment.duration(500).seconds();
Expand Down
13 changes: 12 additions & 1 deletion ts3.1-typings/moment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,22 @@ declare namespace moment {
seconds: number;
milliseconds: number;
}
interface argThresholdOpts {
ss?: number;
s?: number;
m?: number;
h?: number;
d?: number;
w?: number | null;
M?: number;
}

interface Duration {
clone(): Duration;

humanize(withSuffix?: boolean): string;
humanize(argWithSuffix?: boolean, argThresholds?: argThresholdOpts): string;

humanize(argThresholds?: argThresholdOpts): string;

abs(): Duration;

Expand Down
12 changes: 12 additions & 0 deletions typing-tests/moment-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,15 @@ moment(1316116057189).fromNow();
moment.localeData('en');
var globalLang = moment();
var localLang = moment();
var thresholds = {
ss: 44,
s: 45,
m: 45,
h: 22,
d: 26,
w: 2,
M: 11,
};
localLang.localeData();
localLang.format('LLLL');
globalLang.format('LLLL');
Expand Down Expand Up @@ -268,6 +277,9 @@ moment.duration({
});
moment.duration(1, "minute").clone();
moment.duration(1, "minutes").humanize();
moment.duration(1, "minutes").humanize(true);
moment.duration(1, "minutes").humanize(thresholds);
moment.duration(1, "minutes").humanize(true, thresholds);
moment.duration(500).milliseconds();
moment.duration(500).asMilliseconds();
moment.duration(500).seconds();
Expand Down

0 comments on commit 2259e43

Please sign in to comment.