Hacker News new | ask | show | jobs
by pcattori 1233 days ago
Its a Typescript-ism for asserting that the value is not `undefined`. So you're telling the typechecker to trust you on this one
1 comments

Thank you, didn’t know about this one!
That is (was) a good thing! It’s basically the `as any` of strict null checks, and just as unsafe.

Now that you do know about it, please use it sparingly if at all, i.e. when you’re absolutely sure you know more than the type checker, or when you’re in a context where it’ll be caught by other means. My typical lint setup disallows it in source code without an explanatory comment, and allows it in tests under the assumptions that either they’ll fail if wrong or that a reviewer will call out the test as overly complicated.