From 2687a27e3bcaaa52d7d68e4fe8703ccc43c7785a Mon Sep 17 00:00:00 2001 From: Babar Saleh Hayat Date: Thu, 21 Mar 2024 12:22:02 +0500 Subject: [PATCH] Fix for issue #6202: appended null as return type for toJSON --- moment.d.ts | 2 +- src/test/moment/to_type.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/moment.d.ts b/moment.d.ts index 2c5b3cf46b..e75e7c7a3a 100644 --- a/moment.d.ts +++ b/moment.d.ts @@ -589,7 +589,7 @@ declare namespace moment { toDate(): Date; toISOString(keepOffset?: boolean): string; inspect(): string; - toJSON(): string; + toJSON(): string | null; unix(): number; isLeapYear(): boolean; diff --git a/src/test/moment/to_type.js b/src/test/moment/to_type.js index 4881c1fad1..307ed8a3a2 100644 --- a/src/test/moment/to_type.js +++ b/src/test/moment/to_type.js @@ -29,6 +29,8 @@ test('toDate returns a copy of the internal date', function (assert) { }); test('toJSON', function (assert) { + assert.strictEqual(moment(null).toJSON(), null, 'toJSON null'); + if (Date.prototype.toISOString) { var expected = new Date().toISOString(); assert.deepEqual(moment(expected).toJSON(), expected, 'toJSON invalid');