Skip to content
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

Inferring protocol message value as function without ProtocolWithReturn #20

Closed
NoamLoewenstern opened this issue Mar 17, 2023 · 3 comments

Comments

@NoamLoewenstern
Copy link
Contributor

Currently, if a message wants to get response, the way to do that is to use ProtocolWithReturn<data, responseValue>.
But it's possible to infer the type passing a regular function type, and inferring the data-argument and response-value from the type.

Instead of:

interface ProtocolMap {
  getStringLength: ProtocolWithReturn<string, number>;
}

To infer like this:

interface ProtocolMap {
  getStringLength: (str: string) => number;
  messageWithoutResponse: (num: number) => void;
  messageWithoutDataWithResponse: () => number;
}
@aklinker1
Copy link
Owner

aklinker1 commented Mar 17, 2023

Oh wow that's so much cleaner and easier to understand...

Great recommendation! I'll see if I can support this without a breaking change, but I doubt that will be possible. I'll try and release v2 sometime today with this change.

@NoamLoewenstern
Copy link
Contributor Author

I've added to this pull request.
Seems there was an error in the pull-requests' bot deploying to vercel. Odd, since I've changed only a type check.

@aklinker1
Copy link
Owner

aklinker1 commented Mar 17, 2023

Thanks for the PR, I've got it merged and published to v1.3.0. I also updated the docs: https://webext-core.aklinker1.io/messaging/protocol-maps.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants