Skip to content

Commit

Permalink
improve typing
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamlangford committed Jul 9, 2024
1 parent 804ae43 commit 482f52a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/telemetry/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 2 additions & 2 deletions src/telemetry/reportEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -82,7 +82,7 @@ function transformEventData(data: UnknownObject): UnknownObject {
*/
export default function reportEvent<TData extends UnknownObject>(
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);
Expand Down

0 comments on commit 482f52a

Please sign in to comment.