-
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
Compiler API getTypeAtLocation(node) doesn't return Type Alias #6297
Comments
This seems partially related to #6070. |
A reference to a type aliases is meant to eagerly resolve to its aliased type, so we'd have to change the way type aliases themselves are understood within the compiler. I think that's more a technical problem than a philosophical one. |
@DanielRosenwasser - thanks for your response. I think I'll try a different tact in the meantime. So you can close this one if you need to. Is there a good way to subclass the built-in number and string, yet allow those instances to be used in binary expressions with '+-*/' operators? I just looked at #2031 and #2365. |
I think you want to look at #4372. |
@DanielRosenwasser - that is very helpful - thanks again and Happy New Year |
You're very welcome, have a happy new year! |
This is actually by design. the alias is not a separate type. There is only one type, |
First, thanks for making TypeScript. I'm really enjoying this language.
I opened this issue because I'm experiencing an inconsistency or bug in the compiler API surrounding Type Aliases. I like Type Aliases since they are the only way to allow me to differentiate built-in types like number, string, etc. Let me illustrate the issue below.
If I have a class like:
and I compile it, I will get an 'AST'. Here is a portion of the AST.
When I query the VariableStatement or the ExpressionStatement nodes for type via the compiler API using:
tc.getTypeAtLocation(node)
I don't get 'MyString'. I get 'string'.
However, the PropertyDeclaration node has a Type node that properly returns 'MyString'.
If I hover over the statements in Visual Studio Code, I also only see the type 'string'.
To me, this appears like either a bug or a mistake in my attempts at trying to get the information.
I can provide a sample project if needed too.
The text was updated successfully, but these errors were encountered: