News for hackers. Stuff that matters.

joakimbeng

Re:Strong typing, a hill I'm willing to die on on Sunday October 15, 2023 @01:52PM (#37891823)
For such problems we use the Opaque type from the nifty type-fest package. We use it for all of our id types (which are usually numbers) so we can't accidentally mix them.

In your example it would be:

    type Age = Opaque<number, "Age">
And then you wouldn't be able to pass a random number to printAge