From b5e40e6f16abeaea6a0facfa466d20aefaa8a444 Mon Sep 17 00:00:00 2001 From: henry <48340699+imwh0im@users.noreply.github.com> Date: Fri, 2 Jul 2021 16:20:44 +0900 Subject: [PATCH] fix: dayjs ConfigTypeMap add null & undefined (#1560) --- test/parse.test.js | 5 ++++- types/index.d.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/test/parse.test.js b/test/parse.test.js index a8dc739a7..9f2dedf2d 100644 --- a/test/parse.test.js +++ b/test/parse.test.js @@ -89,11 +89,14 @@ describe('Parse', () => { expect(ds.millisecond()).toEqual(ms.millisecond()) }) - it('String Other, Null and isValid', () => { + it('String Other, Undefined and Null and isValid', () => { global.console.warn = jest.genMockFunction()// moment.js otherString will throw warn expect(dayjs('otherString').toString().toLowerCase()).toBe(moment('otherString').toString().toLowerCase()) + expect(dayjs(undefined).toDate()).toEqual(moment(undefined).toDate()) expect(dayjs().isValid()).toBe(true) + expect(dayjs(undefined).isValid()).toBe(true) expect(dayjs('').isValid()).toBe(false) + expect(dayjs(null).isValid()).toBe(false) expect(dayjs('otherString').isValid()).toBe(false) expect(dayjs(null).toString().toLowerCase()).toBe(moment(null).toString().toLowerCase()) }) diff --git a/types/index.d.ts b/types/index.d.ts index 0b9a47622..313f95752 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -10,7 +10,7 @@ declare function dayjs (date?: dayjs.ConfigType, format?: dayjs.OptionType, loca declare namespace dayjs { interface ConfigTypeMap { - default: string | number | Date | Dayjs + default: string | number | Date | Dayjs | null | undefined } export type ConfigType = ConfigTypeMap[keyof ConfigTypeMap]