You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When implementing the first iteration of type aliases, it was a deliberate decision to disallow the use of type aliases as values, because they are types only and do not have a representation at runtime.
For example, all the following is currently disallowed by a dedicated validation:
functionfoo(p: constructor{?}){}classCls{}typeA=Cls;A;// error: A type alias may not be used as a value.newA();// error: A type alias may not be used as a value.foo(A);// error: A type alias may not be used as a value.
However, it would be possible to allow a type alias being used as a value iff it resolves to a type that is also a value (in the above cases, for example). In that case, the transpiler would have to rewrite the reference to the type alias to a reference to the aliased / actual type (in the example above, rewrite references to A to refs to Cls).
Such a use of a type alias as value might be particularly useful in a JSX tag.
At the moment, this ticket is mainly intended to keep track of this topic. It is not yet clear if such a feature is worth the effort/complexity, so this has to be clarified before starting with this user story.
WARNING: supporting this is not trivial, because
the transpiler would have to insert additional imports (if the aliased type is declared in a different module than the type alias),
some invalid cases have to be considered (e.g. what if only the type alias is exported but not the aliased type; what if the aliased type is declared in a different project and no direct project dependency exists to that project?).
The text was updated successfully, but these errors were encountered:
When implementing the first iteration of type aliases, it was a deliberate decision to disallow the use of type aliases as values, because they are types only and do not have a representation at runtime.
For example, all the following is currently disallowed by a dedicated validation:
However, it would be possible to allow a type alias being used as a value iff it resolves to a type that is also a value (in the above cases, for example). In that case, the transpiler would have to rewrite the reference to the type alias to a reference to the aliased / actual type (in the example above, rewrite references to
A
to refs toCls
).Such a use of a type alias as value might be particularly useful in a JSX tag.
At the moment, this ticket is mainly intended to keep track of this topic. It is not yet clear if such a feature is worth the effort/complexity, so this has to be clarified before starting with this user story.
WARNING: supporting this is not trivial, because
The text was updated successfully, but these errors were encountered: