-
Notifications
You must be signed in to change notification settings - Fork 24
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
Allow listeners passed into runtime.onMessage.addListener
to return void
#109
Comments
The people at DefinitelyTyped are a bit hard on disabling their linting rules globally, so this was the easy fix. Can you show me an example where this is an issue for you? I don't believe you need to specify undefined for it to work. |
For reference, this is where the discussion at DT happened: DefinitelyTyped/DefinitelyTyped#69704 So there are 3 ways to solve this:
|
Sure, here's an example: Here's a minimal message listener that logs all received messages: browser.runtime.onMessage.addListener((message) => {
console.log(message);
}); With the updated type definition for
As a result, the message listener needs to include an extra browser.runtime.onMessage.addListener((message) => {
console.log(message);
return undefined;
}); I was hoping that reverting the type definition would be a quick fix, but given the issues you referenced above, I understand the decision you made and agree that it seems like a lot of effort given the upstream challenges. Thanks for following up with me and sharing the context behind it! (Also, as someone who loves type-safety and has been using this library since it was |
I might have found a solution, that even improves types to only allow sendResponse with return true. Let's see if this gets approved: DefinitelyTyped/DefinitelyTyped#72037 |
Previously, listeners for
runtime.onMessage.addListener
could returnPromise<unknown> | true | void
:webextension-polyfill-ts/out/namespaces/runtime.d.ts
Line 584 in b6e8bd1
Currently, they require a return value of
Promise<unknown> | true | undefined
:webextension-polyfill-ts/out/namespaces/runtime.d.ts
Line 583 in 75f8b24
Commit where change was made: 85437fc
I believe the correct type should be
void
rather thanundefined
so that listeners can return without having to specifyundefined
.The text was updated successfully, but these errors were encountered: