Comments (7)
Yeah, this is a long-standing issue with TypeScript, but this problem already existed with Comlink v3.
FWIW, whenever you use bundlers like Rollup you don’t get these errors.
casting as any is the only solution in this case...
Not true :D That is the reason why I set self
to be the default value for expose()
, so this will compile just fine:
expose(Markdown);
from comlink.
Good catch, @lacolaco! Thanks for flagging that.
I pushed 4.0.0-alpha.8
which should fix that issue. Can you please confirm?
from comlink.
@surma the original problem seems solved. thank you!
And now I'm in another situation. it looks a breaking change in typing.
ERROR in src/app/worker/markdown.ts(18,18): error TS2345: Argument of type 'Window' is not assignable to parameter of type 'Endpoint'.
Types of property 'postMessage' are incompatible.
Type '(message: any, targetOrigin: string, transfer?: Transferable[]) => void' is not assignable to type '(message: any, transfer?: any[]) => void'.
Types of parameters 'targetOrigin' and 'transfer' are incompatible.
Type 'any[]' is not assignable to type 'string'.
import * as marked from 'marked';
import { expose } from 'comlink';
export class Markdown {
compile(source: string) {
return new Promise<string>((resolve, reject) => {
marked(source, (err, result) => {
if (err) {
reject(err);
return;
}
resolve(result);
});
});
}
}
expose(Markdown, self); // <---- self is not compatible to Endpoint
I think this is not by design, right?
from comlink.
Comlink v4 has loads of breaking changes :D
Before I start: expose()
passes self
by default now.
But this looks more like TypeScript isn’t aware that you are in a worker context. A simple
declare var self: DedicatedWorkerGlobalScope;
should force TypeScript to assume a worker context.
HTH
from comlink.
It's not easy to solve.
DedicatedWorkerGlobalScope
is declared inwebworker
lib.self
is declared in both ofdom
andwebworker
- so,
dom
andwebworker
are incompatible
- so,
declare var self: DedicatedWorkerGlobalScope;
This line is not valid in dom
context because DedicatedWorkerGlobalScope
is only in webworker
context and Window
and DedicatedWorkerGlobalScope
is not compatible. It's exclusive.
So, if Comlink is used within usual frontend projects, this restriction requires developers to separate tsconfig.json and change transpilation workflow.
from comlink.
casting as any
is the only solution in this case...
expose(Markdown, self as any);
from comlink.
@surma I didn't know about the default value! It's perfect for me. Thank you!
The original issue is solved. I close here.
from comlink.
Related Issues (20)
- Web Worker Hangs if Imported File Contains Top-Level `Await` HOT 6
- Service worker example: stops working when SW is suspended HOT 9
- Set operation is not awaitable HOT 2
- Possible to communicate between web workers? HOT 1
- How to transfer result buffers HOT 2
- [feat] DeasyncEndpoint HOT 2
- Move from Karma to Playwright? HOT 1
- Do I need to use transfer inside a proxy? HOT 1
- Add support for async transferHandle serializer/deserializer HOT 2
- Significant performance optimizations possible in `requestResponseMessage` HOT 4
- Push notifications from web worker HOT 5
- Memory leak when terminating worker with ongoing call HOT 2
- Worker Pool for similar tasks HOT 2
- Sharing constructed objects within a remote context HOT 1
- How to implement comlink in Next.js 14 App Route HOT 2
- Feature request: Automatic proxy of arguments HOT 3
- Having issues when using comlink with react (storing in react state) HOT 3
- Exposed function deadlocks if called too early
- Returning a collection - transferHandlers to be called
- How to prevent auto `releaseProxy`?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from comlink.