Invalid warning for Browser Extensions API listener
Hello,
Am in the process of converting a large JS project to TS.
I'm getting squigglies for lots of functions which used to be fine:
// @see https://developer.chrome.com/extensions/tabs#event-onUpdated
browser.tabs.onUpdated.addListener(function (tabId: number, info: Tabs.OnUpdatedChangeInfoType, tab: Tabs.Tab): void {
delayedUpdate(tabId, tabId, info, tab)
})
Argument type (tabId: number, info: Tabs.OnUpdatedChangeInfoType, tab: Tabs.Tab) => void is not assignable to parameter type ((this:MediaQueryList, ev: MediaQueryListEvent) => any) | null
I think WebStorm is getting muddled, but I'm not sure whether to disable the check in case it disables other checks that are needed.
Strangely, it only happens on some listeners (I have about 6 in the file); see the one below is fine:
browser is part of the Browser Extensions API, and is wrapped by this library:
Can someone advise?
Thanks.
Please sign in to leave a comment.
could you share a sample project the issue can be repeated with?
Sure!
Just this code should work (be sure to `npm install` the dependency):
thanks!
works fine for me when using the provided example:
what declaration is opened when you Ctrl+click on addListener()?
Line 10192 of lib.dom.d.ts:
Maybe I need to flush caches?
are you sure that node_modules/webextension-polyfill-ts folder is included in indexing? Yes, invalidating caches may help
OK. Refactoring an entire project to TS right now, so will finish, get my build working then restart and report back.
Thanks!
Hi Elena,
Annoyingly, the error still remains after invalidating caches.
But... re-reading your replies and I figured it out!
Thanks for your patience in helping me track this down.
What are your thoughts on excluding node_modules?
I find it muddies my general project-wide search results, hence excluding, but this exclude > unexclude technique seems like a great compromise.
It would be cool if there was a way to do this automatically based on package.json...
>It would be cool if there was a way to do this automatically based on package.json...
it's just the way this works by default: the node_modules folder is auto-excluded from indexing, but direct dependencies listed in package.json (plus node_modules/@types, even if they aren't listed there) are added to JavaScript libraries and thus indexed
Oh! Did it always work this way?
I've been using WS for a long time; maybe this is habit I picked up somewhere along the way.
Thanks for the help :)
Have the same issue and it might be a bug of WS.