From 2e7780400e933ca164ce22c1662c8e7be208358d Mon Sep 17 00:00:00 2001 From: Chen Yangjian <252317+cyjake@users.noreply.github.com> Date: Sun, 9 Oct 2022 11:35:14 +0800 Subject: [PATCH] chore: { toDate: () => Date } --- src/data_types.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/data_types.ts b/src/data_types.ts index 383d923a..c50e56ab 100644 --- a/src/data_types.ts +++ b/src/data_types.ts @@ -304,14 +304,14 @@ class DATE extends DataType { return this._round(value); } - uncast(value: null | Raw | string | Date, _strict?: boolean): string | Date | Raw { + uncast(value: null | Raw | string | Date | { toDate: () => Date }, _strict?: boolean): string | Date | Raw { const originValue = value; - if (value == null || value instanceof Raw) return value; + // type narrowing doesn't handle `return value` correctly + if (value == null) return value as null | undefined; + if (value instanceof Raw) return value; // Date | Moment - if (typeof (value as any).toDate === 'function') { - value = (value as any).toDate(); - } + if (typeof value === 'object' && 'toDate' in value) value = value.toDate(); // @deprecated // vaguely standard date formats such as 2021-10-15 15:50:02,548