Any chance of implementing opaque type aliases?


#1

Currently when you create a type alias it’s (AFAICT) purely syntactic sugar for the most part useful in reducing the amount of typing around generics.

What would be nice is a way to create a fully fledged type as an alias for some existing type. For example, I have a custom GUID with some standard factory methods but I want to have an OrderID, ProductID, etc. to al be GUIDs without needing to replicate all the code and without needing to effectively create a composite or other workaround.

Right now I can use type alias but nothing therefore stops me from interchanging the different aliases.


#2

You can just use inheritance.


#3

Hi. Yes that would be the way to go except that it doesn’t work when you have factory methods.


#4

Having ‘distinct types’ as opposed to ‘typealiases’ is something which is being considered as a future feature using ‘inline classes’ as the vehicle.

Check out this recent topic towards the end.