Is it possible to have something like a temporary alias?
Intention (in case if there is maybe an even better alternative):
I want to handle a lot of different unions.
My first idea was to just use it within a method, hoping it would disappear when the method finishes (if there is even really something which can disappear, as if I got it right, an alias exists anyway only pre-compiling) but alias is only allowed on top-level. My usage of alias also doesn’t try to circumvent unions for whatever reason, it’s really just because the code becomes there really difficult to read otherwise.
You can use a private alias, which would only be accessible within the file its defined. E.g.
private alias Foo = Int32 | String. If you need to access it globally, just define your aliases and add
:nodoc: doc comment if you don’t want to expose them as part of the public API.
Another option ofc would be to just use less unions so you don’t need aliases. Ofc depending on the context this might not be possible.
EDIT: To @straight-shoota’s point, a private alias on the top level would be private to the file. A private alias within some namespace would be private to that namespace i think.
Aliases can be defined in any namespace, not just the top-level namespace.