From 2259e43cfefe3a4a306ef25f4db37e0824d32d43 Mon Sep 17 00:00:00 2001 From: Alan Wang Date: Mon, 18 May 2020 12:24:56 +0800 Subject: [PATCH] [bugfix] Update the type definition of the humanize() API, fix compilation error (#5525) --- moment.d.ts | 23 +++++++++++------------ ts3.1-typing-tests/moment-tests.ts | 12 ++++++++++++ ts3.1-typings/moment.d.ts | 13 ++++++++++++- typing-tests/moment-tests.ts | 12 ++++++++++++ 4 files changed, 47 insertions(+), 13 deletions(-) diff --git a/moment.d.ts b/moment.d.ts index 630fc03ab..89ab02fc7 100644 --- a/moment.d.ts +++ b/moment.d.ts @@ -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; diff --git a/ts3.1-typing-tests/moment-tests.ts b/ts3.1-typing-tests/moment-tests.ts index 943738c6d..0ac74ae3a 100644 --- a/ts3.1-typing-tests/moment-tests.ts +++ b/ts3.1-typing-tests/moment-tests.ts @@ -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'); @@ -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(); diff --git a/ts3.1-typings/moment.d.ts b/ts3.1-typings/moment.d.ts index fa90acae3..e100ee3a7 100644 --- a/ts3.1-typings/moment.d.ts +++ b/ts3.1-typings/moment.d.ts @@ -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; diff --git a/typing-tests/moment-tests.ts b/typing-tests/moment-tests.ts index 41cff85cf..a01dd21eb 100644 --- a/typing-tests/moment-tests.ts +++ b/typing-tests/moment-tests.ts @@ -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'); @@ -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(); -- 2.47.2