From 482f52abaf0cb6c47b93a7dce497975ca6344615 Mon Sep 17 00:00:00 2001 From: Graham Langford Date: Tue, 9 Jul 2024 08:54:15 -0500 Subject: [PATCH] improve typing --- src/telemetry/events.ts | 6 ++++-- src/telemetry/reportEvent.ts | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/telemetry/events.ts b/src/telemetry/events.ts index b89c4908b7..b707750773 100644 --- a/src/telemetry/events.ts +++ b/src/telemetry/events.ts @@ -184,6 +184,8 @@ const RESERVED_KEYS = [ "serviceVersion", ] as const; -export type ReservedKeys = { - [K in (typeof RESERVED_KEYS)[number]]?: unknown; +type ReservedKeys = { + [K in (typeof RESERVED_KEYS)[number]]?: never; }; + +export type ReportEventData = UnknownObject & ReservedKeys; diff --git a/src/telemetry/reportEvent.ts b/src/telemetry/reportEvent.ts index f92d36d61e..5ef66d7c2d 100644 --- a/src/telemetry/reportEvent.ts +++ b/src/telemetry/reportEvent.ts @@ -16,7 +16,7 @@ */ import { backgroundTarget as bg, getNotifier } from "webext-messenger"; -import { type Event, type ReservedKeys } from "@/telemetry/events"; +import { type Event, type ReportEventData } from "@/telemetry/events"; import { expectContext } from "@/utils/expectContext"; expectContext( @@ -82,7 +82,7 @@ function transformEventData(data: UnknownObject): UnknownObject { */ export default function reportEvent( event: Event, - data: TData extends ReservedKeys ? never : TData = {} as never, + data: ReportEventData = {}, ): void { // eslint-disable-next-line prefer-rest-params -- Needs `arguments` to avoid printing the default console.debug(...arguments);