found a neat use for 's new opaque type aliases: type safe stringified values. errors if an unknown/arbitrary string is passed
Conversation
Was wanting this recently for tagging various IDs. Would really reduce the chance of mixing them up and allow for type-driven refactors.
This was the motivating use case for opaque types!
Isn't it still safer / easier to enumerate possible values in `type S = 'someid' | 'otherid'`? Works even in the same file.
1
1
if it's practical to enumerate all valid ids, sure, but if eg. valid ids = string of any number in a large range then it's not practical
1
1
Show replies



