From 397e7bc40a33ee37f911638aeb55997aea9dfda9 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Wed, 5 Apr 2023 20:42:34 +0800 Subject: [PATCH] type: fix type error. --- src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 55fd613c..f842f5c7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -17,17 +17,17 @@ function formatter(str?: string, date?: Date, utc?: boolean): string { str = 'YYYY-MM-DD'; } - return str.replace(dateRegex, (match: string, key: string, rest?: string) => { + return str.replace(dateRegex, (match: string, key: keyof typeof timespan, rest?: string) => { const args = timespan[key]; const chars = args[1]; - let name = args[0]; + let name = args[0] as keyof Date; if (utc === true) { - name = `getUTC${name.slice(3)}`; + name = `getUTC${String(name).slice(3)}` as keyof Date; } if (!date) { date = new Date(); } - const val = `00${String(date[name]() + (args[2] || 0))}`; + const val = `00${String((date[name] as typeof Date)() + (args[2] || 0))}`; return val.slice(-chars) + (rest || ''); }); }