diff --git a/packages/core/useWebWorker/index.md b/packages/core/useWebWorker/index.md index a06f4daf8cf..9dff64baf24 100644 --- a/packages/core/useWebWorker/index.md +++ b/packages/core/useWebWorker/index.md @@ -20,7 +20,7 @@ const { data, post, terminate, worker } = useWebWorker('/path/to/worker.js') | data | `Ref` | Reference to the latest data received via the worker, can be watched to respond to incoming messages | | worker | `ShallowRef` | Reference to the instance of the WebWorker | -| Method | Signature | Description | -| --------- | --------------------- | -------------------------------- | -| post | `(data: any) => void` | Sends data to the worker thread. | -| terminate | `() => void` | Stops and terminates the worker. | +| Method | Signature | Description | +| --------- | ------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- | +| post | `(message: any, transfer: Transferable[]): void`
`(message: any, options?: StructuredSerializeOptions | undefined): void` | Sends data to the worker thread. | +| terminate | `() => void` | Stops and terminates the worker. | diff --git a/packages/core/useWebWorker/index.ts b/packages/core/useWebWorker/index.ts index db9077fd8f4..edc4a88a073 100644 --- a/packages/core/useWebWorker/index.ts +++ b/packages/core/useWebWorker/index.ts @@ -6,9 +6,11 @@ import { tryOnScopeDispose } from '@vueuse/shared' import type { ConfigurableWindow } from '../_configurable' import { defaultWindow } from '../_configurable' +type PostMessage = typeof Worker.prototype['postMessage'] + export interface UseWebWorkerReturn { data: Ref - post: typeof Worker.prototype['postMessage'] + post: PostMessage terminate: () => void worker: ShallowRef } @@ -51,11 +53,11 @@ export function useWebWorker( const data: Ref = ref(null) const worker = shallowRef() - const post: typeof Worker.prototype['postMessage'] = function post(val: any) { + const post: PostMessage = (...args) => { if (!worker.value) return - worker.value.postMessage(val) + worker.value.postMessage(...args as Parameters) } const terminate: typeof Worker.prototype['terminate'] = function terminate() {