TypeScript typings seem off when wrapping an object graph
Author: jderemerCreated Aug 8, 2025Updated Aug 8, 2025
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.
Source: GoogleChromeLabs/comlink