Re:Don't Use Booleans
by hardwaresofton on Tuesday July 09, 2024 @08:29PM
(#40922711)
Thanks for the snippet, it is INTENSE. Will see what I can learn from it — const array I definitely didn’t consider before!
The gist is: define your enum values as a const array. Then you can generate a TypeScript type based on whatever values you have in there. And, since it's an actual array, you can easily write guards / asserts.
So you end up with something easy to extend and also has compile-time and run-time checks.