webext-core icon indicating copy to clipboard operation
webext-core copied to clipboard

defineExtensionMessaging should be marked with `this: void`

Open minht11 opened this issue 1 year ago • 3 comments

Basically the same idea as with https://typescript-eslint.io/rules/unbound-method/ so tooling knows destructoring is safe here.

https://github.com/aklinker1/webext-core/blob/ce0ad0d78de9feff2c91a239cd42294d989e6819/packages/messaging/src/extension.ts#L49-L51

function defineExtensionMessaging(this: void, condig: Config)

minht11 avatar Nov 21 '24 22:11 minht11

Just being a static function already means that it's this is void. The lint rule you linked to only mentions bound functions and changing the this context, but that doesn't apply to non-class functions. And it doesn't mention anything about making destructuing safe... Am I misunderstanding what you're asking for?

aklinker1 avatar Nov 22 '24 15:11 aklinker1

Currently that lint rule fails for me, hence this issue report. I think I was bit wrong this should not be declared on defineExtensionMessaging but on sendMessage instead https://github.com/aklinker1/webext-core/blob/ce0ad0d78de9feff2c91a239cd42294d989e6819/packages/messaging/src/generic.ts#L40-L59

Not 100% sure but interface/class when used as a type behaves almost the same, so when it sees GenericMessenger interface which you try destructoring from it thinks this could belong to GenericMessenger and not be void

minht11 avatar Nov 22 '24 15:11 minht11

Yeah ok, that makes more sense. If you want to open a PR, that'd be great

aklinker1 avatar Nov 22 '24 15:11 aklinker1