-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to pass "unique symbol" as a type parameter (e.g. Opaque<string, unique symbol>). #55691
Comments
^^^ what he said. |
Those are good workarounds but they are workarounds.
That's not true. For example: type UserId = string & { readonly __brand: unique symbol };
Not sure what you mean by that. |
It means exactly what I said. Your own example is of creating two |
By this reasoning, what you’re trying to do is a workaround too and you ultimately really want #202. You have to compromise somewhere. |
I am not sure I understand why are you opposed to this feature? Because there are workarounds? |
Not opposed per se, just pointing out the opposite: if you’re opposed to being forced to use workarounds, then adding a feature whose only apparent purpose is to make what’s already a hacky workaround for the stated use case easier doesn’t seem like the way to go. |
What seems like the way to go? |
I agree that #202 would be ideal but it has been opened for almost 10 years and it could be opened for another 10 years. While the feature I propose is not be a big change, it's even arguably a bug. |
This can’t be done without allowing type Id<T> = T; // obviously legal type alias declaration
type X1 = unique symbol; // error: 'unique symbol' types are not allowed here
type X2 = Id<unique symbol>; // instantiation is legal but results in the same type as X1, which is illegal? |
This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
✅ Viability Checklist
⭐ Suggestion
I have been trying to write a type helper to facilitate the creation of nominal types (aka branded/tagged/opaque types), but I'm a bit stuck by the fact I can't pass
unique symbol
as a type parameter.The following doesn't work:
And if I just get rid of the TBrand parameter, it considers both UserId and GroupId to be compatible.
📃 Motivating Example
See suggestion.
💻 Use Cases
Creating nominal types
Have to memorize how to do it, more code to type.
To do the nominal type without using a type helper.
The text was updated successfully, but these errors were encountered: