From f549f18ce09286d7249b8642e9a425ad1f2c57d5 Mon Sep 17 00:00:00 2001 From: Ashley Harrison Date: Tue, 29 Aug 2023 15:33:03 +0100 Subject: [PATCH] fix types --- .betterer.results | 4 +--- .../grafana-data/src/datetime/moment_wrapper.ts | 14 +++++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.betterer.results b/.betterer.results index 889c10484a1..033dd17328e 100644 --- a/.betterer.results +++ b/.betterer.results @@ -118,9 +118,7 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "5"], [0, 0, 0, "Do not use any type assertions.", "6"], [0, 0, 0, "Do not use any type assertions.", "7"], - [0, 0, 0, "Do not use any type assertions.", "8"], - [0, 0, 0, "Do not use any type assertions.", "9"], - [0, 0, 0, "Do not use any type assertions.", "10"] + [0, 0, 0, "Do not use any type assertions.", "8"] ], "packages/grafana-data/src/datetime/parser.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], diff --git a/packages/grafana-data/src/datetime/moment_wrapper.ts b/packages/grafana-data/src/datetime/moment_wrapper.ts index 5969eaf89ad..33f53fb0a17 100644 --- a/packages/grafana-data/src/datetime/moment_wrapper.ts +++ b/packages/grafana-data/src/datetime/moment_wrapper.ts @@ -131,9 +131,17 @@ export const dateTimeForTimeZone = ( } if (timezone && timezone !== 'browser') { - // TODO fix types here - //@ts-ignore - return moment.tz(input as MomentInput, formatInput, timezone) as DateTime; + let result: moment.Moment; + + if (typeof input === 'string' && formatInput) { + result = moment.tz(input, formatInput, timezone); + } else { + result = moment.tz(input, timezone); + } + + if (isDateTime(result)) { + return result; + } } return dateTime(input, formatInput);