easy-web-worker 8.0.0 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/types.d.ts +18 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easy-web-worker",
3
- "version": "8.0.0",
3
+ "version": "8.0.1",
4
4
  "description": "This is a library to easily handle and create web-workers, if you are a web developer and never tried this... do not wait any longer! Workers are an amazing option to improve user experience and make your webpages even greater",
5
5
  "main": "./bundle.cjs",
6
6
  "module": "./bundle.mjs",
package/types.d.ts CHANGED
@@ -154,6 +154,22 @@ export type TOverrideConfig = {
154
154
  * @template IResult - Indicates if your WORKERS messages has a result... NULL indicates all you messages are Promise<void>
155
155
  * @param {IEasyWorkerInstance<IPayload, IResult>} easyWorker - ,
156
156
  */
157
+ /**
158
+ * Global scope of a dedicated worker, as the `webworker` lib of TypeScript declares it.
159
+ * It is read from the global types instead of named, so the declarations of this package also compile in
160
+ * a project that only loads the `dom` lib. There, the scope falls back to the members every worker has.
161
+ */
162
+ type NativeWorkerScope = typeof globalThis extends {
163
+ DedicatedWorkerGlobalScope: {
164
+ prototype: infer TScope;
165
+ };
166
+ } ? TScope : EventTarget & {
167
+ readonly name: string;
168
+ readonly self: unknown;
169
+ postMessage(message: any, transfer?: Transferable[]): void;
170
+ importScripts(...urls: (string | URL)[]): void;
171
+ close(): void;
172
+ };
157
173
  export type EasyWebWorkerBody<IPayload = null, IResult = void, TPrimitiveParameters extends any[] = unknown[]> = (
158
174
  /**
159
175
  * This is the instance of the worker that you can use to communicate with the main thread
@@ -162,7 +178,7 @@ easyWorker: IEasyWorkerInstance<IPayload, IResult>,
162
178
  /**
163
179
  * This is the context of the worker, you can use it to access to the global scope of the worker
164
180
  * */
165
- context: DedicatedWorkerGlobalScope & {
181
+ context: NativeWorkerScope & {
166
182
  primitiveParameters: TPrimitiveParameters;
167
183
  } & Record<string, unknown>) => void;
168
184
  export type TMessagePostType = 'progress' | 'resolved' | 'rejected' | 'canceled' | 'worker_cancelation';
@@ -275,7 +291,7 @@ export type WorkerHelpers = {
275
291
  /**
276
292
  * Global scope of the worker
277
293
  */
278
- export type WorkerScope<TPrimitiveParameters extends any[] = unknown[]> = DedicatedWorkerGlobalScope & {
294
+ export type WorkerScope<TPrimitiveParameters extends any[] = unknown[]> = NativeWorkerScope & {
279
295
  /**
280
296
  * Values of the primitiveParameters option, only for the workers created from a function
281
297
  */