Incompatible between browser.tabs.query and browser.tabs.update
See original GitHub issueHi! I have this code:
import { browser } from 'webextension-polyfill-ts';
async function fn() {
const tabs = await browser.tabs.query({});
browser.tabs.update(tabs[0].id, {active: true});
}
And ts shows error on tabs[0].id:
TS2345: Argument of type ‘number | undefined’ is not assignable to parameter of type ‘number’. Type ‘undefined’ is not assignable to type ‘number’.
is it intended or a bug?
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
tabs.update() - Mozilla - MDN Web Docs
This is an asynchronous function that returns a Promise . Syntax. let updating = browser.tabs.update( ...
Read more >Tabs cannot be queried right now (user may be dragging a tab)
I found that the real reason is: when you click the mouse to switch tabs, when chrome.tabs.
Read more >How tabs should work - Remy Sharp
I used to be from the school of using the hash to show the right tab, but I've recently been exploring whether the...
Read more >Q. Why can't I have Gladly running on multiple browser tabs?
For example, moving between two Gladly sessions on separate browser tabs may cause inconsistent time tracking.
Read more >Supported APIs for Microsoft Edge extensions
When building extensions for the Microsoft Edge browser, ... sessions, Query and restore tabs and windows from a browsing session.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Sure. I’m sure you know, that in TypeScript, optional parameters may not be followed by non-optional parameters:
The previous approach to solve this was like this: If a function has non-optional parameters following optional parameters, do:
optionalflag from the first non-optional parameter, and generate the code for this modified function (a recursive call, i.e. it might again do this trick)Example:
The new approach does the same thing, but instead of removing the
optionalflag, it sets an internaloverloadFlag. If this is set, then the parameter doesn’t match when looking for the first optional parameter that is followed by a non-optional parameter. That way, theoptionalflag stays in the parameter and I use it later to add the “| undefined” instead of the “?”.Example:
The commit for this was: https://github.com/Lusito/webextension-polyfill-ts/commit/cf4f93db834e49ee485453769675f4282b66b1c5
@vitalets I’ve released a new version, which fixes the issue.