News for hackers. Stuff that matters.
Re:Don't Use Booleans by c-hendricks on Tuesday July 09, 2024 @02:46PM (#40919458)
I've done things like this before: https://www.typescriptlang.org/play/?#code/PTAEAkFMBsAdIE4Gc...

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.

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!