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
Notably, note that the definition for aliasTypeArguments is not inside the object type, but rather annotated to the whole union expression. If you look at the AST for the anonymous object type, however, you will find the following:
Notice that both in its TypeObject and its target, there value for aliasTypeArguments is undefined.
This explains why visitTypeAliasReference is never called (recall: it only gets called if type.aliasTypeArguments && type.target which doesn't hold for our case).
Instead, we are provided with a mapper data structures that map our target to the aliasTypeArguments definition:
Can we use mapper?
mapper is not part of the public typescript API it seems, so we can't use it. It's slightly unfortunate because the usage is extremely simple
This mapper field is also present (but ignored) in other cases of AST parsing, so I'm not sure what the impact of using it here would be either.
Can we use instantiations?
This field also seems like in the general case it isn't part of the public API. It looks like it might enough information to rebuild what we want, but I'm not familiar enough with the AST to know if this is really the right approach.
Investigation conclusion
I'm not really sure where to go next on this one. It seems to tackle one of the assumptions on the Typescript AST used for this codebase so I'm not really sure if I should change it. The mapper solution works, but I'm not knowledgeable to know the implications of this solution or whether or not it's the right approach so I'd love any help on this
The text was updated successfully, but these errors were encountered:
typeNoop<Value>={data: Awaited<Promise<Value>>}is<Noop<5>>({data: 5})// throw an error
In this case, the failure case it will throw an error because if ((ts.TypeFlags.Conditional & type.flags) !== 0) isn't checked in the visitType or type-check or type-name, but it seems strange this would be an issue where as the version not wrapped in an object works perfectly and again, in the failure case, the target & aliasTypeArguments are at different levels in the stack
Background
Consider the test case in PR #115
It works well when the use of the generic is in the top-level of the type. Notably, the visit order will look something like this
Notice the first thing in the parsing order will be the
aliasReference
.However, now consider the modified definition given below
This modified code instead gives the following visit order
Notice that the call to
visitTypeAliasReference
is missing and therefore the call tovisitTypeParameter
will fail.Generated AST
If you look at the definition of the root type (the type representing the union), it has the following AST
Notably, note that the definition for
aliasTypeArguments
is not inside the object type, but rather annotated to the whole union expression. If you look at the AST for the anonymous object type, however, you will find the following:Notice that both in its TypeObject and its
target
, there value foraliasTypeArguments
is undefined.This explains why
visitTypeAliasReference
is never called (recall: it only gets called iftype.aliasTypeArguments && type.target
which doesn't hold for our case).Instead, we are provided with a
mapper
data structures that map our target to the aliasTypeArguments definition:Can we use mapper?
mapper
is not part of the public typescript API it seems, so we can't use it. It's slightly unfortunate because the usage is extremely simpleThis
mapper
field is also present (but ignored) in other cases of AST parsing, so I'm not sure what the impact of using it here would be either.Can we use instantiations?
This field also seems like in the general case it isn't part of the public API. It looks like it might enough information to rebuild what we want, but I'm not familiar enough with the AST to know if this is really the right approach.
Investigation conclusion
I'm not really sure where to go next on this one. It seems to tackle one of the assumptions on the Typescript AST used for this codebase so I'm not really sure if I should change it. The
mapper
solution works, but I'm not knowledgeable to know the implications of this solution or whether or not it's the right approach so I'd love any help on thisThe text was updated successfully, but these errors were encountered: