DEV Community

Discussion on: Boolean - The Good, The Bad and there is no place for the Ugly

Collapse
 
macsikora profile image
Pragmatic Maciej

Hi Sam. Thanks for the comment.
Yes Booleans are fine. But I see in this particular example and in many others even for two possible values I would choose some Union type. The reason is that Bool is not informative enough. So if you have property isAdmin and it is false, then you know that the user is not an admin, but who is the user, still you don't know.

And by custom type (enum, union) it can be easily defined. So I can set a type like (not TS notation) Admin | Manager or Admin | Client and so on. And I can define who is this second part. I know then, not only that somebody is not an admin, but I know who exactly he is.

In other words, such type gives identity to every option existing in our type.