Skip to content

Commit 4c38041

Browse files
committed
don't break ts setups, fix tests
1 parent 49cbdca commit 4c38041

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

dev-packages/e2e-tests/test-applications/browser-webworker-vite/src/worker.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as Sentry from '@sentry/browser';
22

3-
// type cast necessary because TS thinks this file is part of the main
4-
// thread where self is of type `Window` instead of `Worker`
5-
Sentry.registerWebWorker({ self: self as unknown as Worker });
3+
Sentry.registerWebWorker({ self });
64

75
// Let the main thread know the worker is ready
86
self.postMessage({

dev-packages/e2e-tests/test-applications/browser-webworker-vite/src/worker2.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as Sentry from '@sentry/browser';
22

3-
// type cast necessary because TS thinks this file is part of the main
4-
// thread where self is of type `Window` instead of `Worker`
5-
Sentry.registerWebWorker({ self: self as unknown as Worker });
3+
Sentry.registerWebWorker({ self });
64

75
// Let the main thread know the worker is ready
86
self.postMessage({

dev-packages/e2e-tests/test-applications/browser-webworker-vite/src/worker3.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as Sentry from '@sentry/browser';
22

3-
// type cast necessary because TS thinks this file is part of the main
4-
// thread where self is of type `Window` instead of `Worker`
5-
Sentry.registerWebWorker({ self: self as unknown as Worker });
3+
Sentry.registerWebWorker({ self });
64

75
// Let the main thread know the worker is ready
86
self.postMessage({

dev-packages/e2e-tests/test-applications/browser-webworker-vite/tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
"target": "ES2022",
44
"useDefineForClassFields": true,
55
"module": "ESNext",
6-
"lib": ["ES2022", "DOM", "DOM.Iterable"],
7-
"skipLibCheck": true,
6+
"lib": ["ES2022", "DOM", "DOM.Iterable", "WebWorker"],
7+
"skipLibCheck": false,
8+
"skipDefaultLibCheck": true,
89

910
/* Bundler mode */
1011
"moduleResolution": "bundler",

packages/browser/src/integrations/webWorker.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,21 @@ function listenForSentryDebugIdMessages(worker: Worker): void {
113113
});
114114
}
115115

116+
/**
117+
* Minimal interface for DedicatedWorkerGlobalScope, only requiring the postMessage method.
118+
* (which is the only thing we need from the worker's global object)
119+
*
120+
* @see https://developer.mozilla.org/en-US/docs/Web/API/DedicatedWorkerGlobalScope
121+
*
122+
* We can't use the actual type because it breaks everyone who doesn't have {"lib": ["WebWorker"]}
123+
* but uses {"skipLibCheck": true} in their tsconfig.json.
124+
*/
125+
interface MinimalDedicatedWorkerGlobalScope {
126+
postMessage: (message: unknown) => void;
127+
}
128+
116129
interface RegisterWebWorkerOptions {
117-
self: DedicatedWorkerGlobalScope & { _sentryDebugIds?: Record<string, string> };
130+
self: MinimalDedicatedWorkerGlobalScope & { _sentryDebugIds?: Record<string, string> };
118131
}
119132

120133
/**

0 commit comments

Comments
 (0)