-
Notifications
You must be signed in to change notification settings - Fork 421
Open
Description
The web worker that I'm wrapping looks like:
worker.js
interface MyWebWorker {
service: {
method: () => void;
};
}
Comlink.expose({
service: {
method: () => {}
}
})
main.js
const worker = new Worker("worker.js");
const obj = Comlink.wrap<MyWebWorker>(worker);
After wrapping in main.js, I get the following typings:
- obj:
Remote<MyWebWorker> - obj.service:
Promise<{ method: () => void }>
What I would like/expect is the following typings:
- obj:
Remote<MyWebWorker> - obj.service:
{ method: () => void } - obj.service.method:
() => Promise<void>
At runtime, I can run obj.service.method() and it will successfully make the call to the web worker.
But at compile time, Typescript says Property 'method' does not exist on type 'Promise<{ method: () => void }>'.
My desired typings feel possible based on how it works at runtime, but the typing of Remote<T> seems to just wrap everything in the object graph with promises.
whalderman and Vyachean
Metadata
Metadata
Assignees
Labels
No labels