fix: Remove unsafe non-null assertions by gonfunko · Pull Request #9598 · RaspberryPiFoundation/blockly

The main issue here (and throughout Blockly in general) is that lots of things are not actually initialized in the constructor, but rather in some init/createDom method. That means they have to be treated as nullable, but de facto aren't. That's the case here as well; flyout, HtmlDiv, and contentsDiv_ are all initialized by init(), which is called from Blockly.inject(). Being called directly from inject() is about as close to a guarantee of "this will always happen" as we can get, and I think just having ?. to satisfy TS is adequate.

The bug that led to this PR is a bit different in that we do allow adding arbitrary items to the toolbox. We're already only selecting them if they're selectable, so I think only doing that in the case that we were able to successfully look up the item in the first place is fine, and certainly preferable to throwing.