-
Notifications
You must be signed in to change notification settings - Fork 400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix TypeScript types #451
Fix TypeScript types #451
Conversation
cc2f421
to
0082ce7
Compare
This is stellar work, @felixfbecker. Thanks for that. I gave it a skim, but gonna need a bit more time to look at it in detail. Either way, thanks for working through this. I’ll get back to this soon! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is amazing work! Than you very much!
The only major thing that needs fixing (I think) is the fact that proxyMarked
is being used on the remote side.
Other than that I’m happy to merge it once TS 3.9 goes stable.
Thanks for the review! I addressed all comments :) |
This fixes the typings issues described in #432.
Promisify<T>
needs to check first whetherT extends Promise
already. Otherwise it could resolve toPromise<Promise<T>>
ifT
already is a Promise (which is impossible in comlink and JavaScript in general).In the mapped types, each right side generally needs to be extracted into its own type alias. This is because generic type aliases will distribute over union types, while inlining the type would not. This means the type would not work properly when union types are involved. This may sound like an edge case, but includes e.g. optional properties, which are union types
xxx | undefined
.(most complicated part) For proxied functions, while the return type needs to be wrapped in
Remote<T>
, the parameters of the functions need to have the inverse applied. This is because from the point of view of the function implementation, passed callbacks will now return Promises, and therefor they need to type their signature accordingly. But the caller does not actually need to provide a callback that returns a Promise, from the point of view of the caller it just needs to pass a synchronous callback.[releaseProxy]
and[createEndpoint]
also need to be considered (i.e. not required to be provided by a caller).The first commit adds tests that fail on master. I upgraded to TypeScript 3.9 to get access to
@ts-expect-error
and added a tsconfig.json so that strict mode is applied to the tests too.The second commit overhauls the actual types to fix all the failing tests.
I did my best to write as many comments as possible to explain them, but the types are no doubt complex. The result is that users don't have to worry about any of this because it "just works" under the hood :)
Also fixes #424 in a type-safe way.