Skip to content

Commit 1dc0f02

Browse files
committed
fix(analytics): change method return types from void to Promise<void>
The Analytics interface declared track(), page(), identify(), and setEnabled() as returning void. The background implementation returns Promise<void> (async functions), which is assignable to void. But users calling await analytics.track() get TS80007 since the declared type is void. Changed the interface return types to Promise<void> and updated the MethodForwarder type and implementation accordingly.
1 parent 22b7aba commit 1dc0f02

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

packages/analytics/modules/analytics/client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type AnalyticsMethod =
2525

2626
type MethodForwarder = <K extends keyof Analytics>(
2727
fn: K,
28-
) => (...args: Parameters<Analytics[K]>) => void;
28+
) => (...args: Parameters<Analytics[K]>) => Promise<void>;
2929

3030
const ANALYTICS_PORT = '@wxt-dev/analytics';
3131

@@ -238,6 +238,7 @@ function createFrontendAnalytics(): Analytics {
238238
(fn) =>
239239
(...args) => {
240240
port.postMessage({ fn, args: [...args, getFrontendMetadata()] });
241+
return Promise.resolve();
241242
};
242243

243244
const analytics: Analytics = {

packages/analytics/modules/analytics/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
export interface Analytics {
22
/** Report a page change. */
3-
page: (url: string) => void;
3+
page: (url: string) => Promise<void>;
44
/** Report a custom event. */
55
track: (
66
eventName: string,
77
eventProperties?: Record<string, string | undefined>,
8-
) => void;
8+
) => Promise<void>;
99
/** Save information about the user. */
10-
identify: (userId: string, userProperties?: Record<string, string>) => void;
10+
identify: (userId: string, userProperties?: Record<string, string>) => Promise<void>;
1111
/**
1212
* Automatically setup and track user interactions, returning a function to
1313
* remove any listeners that were setup.
1414
*/
1515
autoTrack: (root: Document | ShadowRoot | Element) => () => void;
1616
/** Calls `config.enabled.setValue`. */
17-
setEnabled: (enabled: boolean) => void;
17+
setEnabled: (enabled: boolean) => Promise<void>;
1818
}
1919

2020
export interface AnalyticsConfig {

0 commit comments

Comments
 (0)