Skip to content
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

[Question] node.getType().getText() vs node.getType().getText(node) #923

Closed
stacey-gammon opened this issue Jan 27, 2021 · 1 comment
Closed
Labels

Comments

@stacey-gammon
Copy link

This is somewhat related to my question here: #907

I'm relying on the import paths inside the returned string from node.getType().getText() to build reference links in an API doc system. node.getType().getText(node) always strips these import paths, but sometimes it returns better information than when not supplying the node.

Is there any way to get both the more complete information, but keep the import paths? I made a table of these differences here:

Screen Shot 2021-01-27 at 1 09 03 PM

There are some pretty interesting results. Notice how KindOfADup actually returns a reference to Foo because their types overlap, though they are defined separately.

Link to codesandbox

@dsherret
Copy link
Owner

Probably to get more complete information you could inspect the Type objects themselves then once having a type reference, maybe looking at .getSymbol() and then following the symbols to the declaration (using Symbol#getAliasedSymbol() might help you travel). It will be a bit of code to write though.

Notice how KindOfADup actually returns a reference to Foo because their types overlap, though they are defined separately.

Yeah, it's annoying and unfortunate that the ts compiler does this ☹. See here: microsoft/TypeScript#28197

@dsherret dsherret reopened this Apr 3, 2021
@dsherret dsherret closed this as completed Apr 3, 2021
Repository owner locked and limited conversation to collaborators Apr 3, 2021
Repository owner unlocked this conversation Apr 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants