This is an excellent example of necessary error-checking stuff; user-agent feature detection (which includes the browser’s baseline functionality which is basically a completely uncontrolled third-party library, the worst situation by far) is another good example. But it’s extremely easy to take it too far. Any library stuff that gets bundled into your code, you should prefer compile-time to runtime type-checking. But anything outside, yeah, then you have to decide.
If it's your own code that does no IO then yeah it's more ok to trust TypeScript.
Same with user input code. You can trust your implementation to the extent of static type checking and analysis. You can't trust anything a user entered into your system. Those are examples of the externals that I stated you can't trust.
Although I'm a huge fan of TypeScript and use it and a bundle in all my UIs, you cannot guarantee that everything was typed correctly or that things haven't escaped being typed.
Sometimes I wonder if the right thing is to actually guard every object from being undefined like this sample. It does seem crazy.
This is basically a problem for every language with metaprogramming/eval/LD_PRELOAD: you can't necessarily truly count on things being defined like you think they are. That also starts getting pretty paranoid but again the topic here is resilience so should you ignore that things can/actually do change under the hood when you don't expect?