0

browser.tabs.query returns Tab objects, which have an optional id attribute. So every time I access this id, my IDE "helpfully" warns me that the id might be undefined.

Can I safely ignore this warning or can tabs.query() actually return a Tab with no id?

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
  • if it’s optional, then, by definition, it can be omitted. whether this is true in a particular case doesn’t even matter. you should know and handle the fact that it is in fact optional. you never know what’s going to happen in the future. – Psi Oct 02 '22 at 09:05
  • @Psi It's still useful to know under what circumstances I'll get a tab with no id, because then maybe I can find a workaround instead of just crashing. Or at least display a nice(r) error message. – Aran-Fey Oct 02 '22 at 09:15
  • I get your point, but I‘d handle the case in any condition that may or may not be known in advance. if it’s optional, it’s always better to test for its existence and handle the case where it’s missing gracefully – Psi Oct 02 '22 at 14:57

0 Answers0