Groups
Conversations
All groups and messages
Send feedback to Google
Help
Training
Sign in
Groups
PiLuD
Conversations
About
Groups keyboard shortcuts have been updated
Dismiss
See shortcuts
TypeScript branded types
1 view
Skip to first unread message
Mike Austin
unread,
Feb 13, 2025, 3:24:51 PM
Feb 13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to PiLuD
type uuid = string & { __type: "uuid"; };
function uuid(value: string): uuid {
if (!(...).test(value)) {
throw Error("Not a valid UUID");
}
return value as uuid;
}
Now strings are not compatible with uuids. I had a feeling TypeScript could do it.
More details:
Leveraging TypeScript branded types for stronger type checks - LogRocket Blog
Reply all
Reply to author
Forward
0 new messages