logoalt Hacker News

kleibayesterday at 4:21 PM4 repliesview on HN

What have you gained?


Replies

munk-ayesterday at 4:38 PM

Without any other context? Nothing - it's just a type alias...

But the context this type of an alias should exist in is one where a string isn't turned into a PhoneNumber until you've validated it. All the functions taking a string that might end up being a PhoneNumber need to be highly defensive - but all the functions taking a PhoneNumber can lean on the assumptions that go into that type.

It's nice to have tight control over the string -> PhoneNumber parsing that guarantees all those assumptions are checked. Ideally that'd be done through domain based type restrictions, but it might just be code - either way, if you're diligent, you can stop being defensive in downstream functions.

show 3 replies
esafakyesterday at 5:59 PM

Validation, readability, and prevention of accidentally passing in the wrong string (e.g., by misordering two strings arguments in a function).

jalkyesterday at 4:28 PM

An explicit type

show 1 reply
waynesonfireyesterday at 4:58 PM

What did you lose?