News for hackers. Stuff that matters.
Re:Go-like channels in 10 lines of JavaScript by sesm on Saturday February 04, 2023 @06:02PM (#34659350)
I don’t understand why there is a bang operator in the last code sample on line 18. Is it a typo?
Re:Go-like channels in 10 lines of JavaScript by pcattori on Saturday February 04, 2023 @06:02PM (#34659358)
Its a Typescript-ism for asserting that the value is not `undefined`. So you're telling the typechecker to trust you on this one
Re:Go-like channels in 10 lines of JavaScript by sesm on Saturday February 04, 2023 @06:05PM (#34659374)
Thank you, didn’t know about this one!
Re:Go-like channels in 10 lines of JavaScript by eyelidlessness on Saturday February 04, 2023 @07:29PM (#34660125)
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.