4 ms·
> It's more of an issue of no runtime type safety... This is a completely orthogonal question to soundness.
by lolinder 2y ago
> It's more of an issue of no runtime type safety...
This is a completely orthogonal question to soundness.
- leononame 2y agoIn this case, not really. TypeScript can't be sound because there is zero runtime type safety in JS. That you are able to do `as unknown as T` makes TypeScript unsound, but it's also an escape hatch often needed to interact with JavaScript's dynamic typing.
- ffsm8 2y ago> an escape hatch often needed The only time you need that is in tests. Otherwise you're better off using guards then blindly casting
- tuwtuwtuwtuw 2y agoThe code base I work on has more test code than production code.
- lolinder 2y ago> often needed It's never needed, it's just often convenient for something quick and dirty. You can always write a guard to accomplish the same thing—roll your own runtime safety. If you want to avoid doing it manually there's Zod. It's not that much different than writing a binding for a C library in another language in that you're manually enforcing the constraints of your app at the boundaries.