3 ms·
Agreed! Expanded type guards can replace a huge amount of unit tests in a way that is more concise and provides a better promise to more of the code. It's abo
by throwaway13337 3y ago
Agreed!
Expanded type guards can replace a huge amount of unit tests in a way that is more concise and provides a better promise to more of the code.
It's about orientation. Orienting around the data makes so much more sense. Why test every function's email address param when you can instead guard via an email address type?
Typescript is the most popular language to try and their type system is a lot of fun. However, the compiler messages remind me of working with Boost libs in C++. It's also unfortunate that typescript actually provides no guarantee about runtime so I never have complete confidence like I do with real static typed languages.
You can also get to a point in typescript where you go down a type system rabbit hole and find yourself a code philosopher. It's been a personal black hole for time wasting on a project for me.
Libs like Zod go a long way in JS and they accomplish the same but better for me. They leverage typescript and you get compile time and runtime support.
Vogan in C# provides compile time warnings but uses generated code to achieve it. It is impressive what the new code generation support in C# can do now.
Still, it would be nice to have first class support from a language.
https://github.com/colinhacks/zod https://github.com/colinhacks/zod
https://github.com/SteveDunn/Vogen https://github.com/SteveDunn/Vogen