Skip to content

typeChecker.typeToString() should print most derived alias #19198

@jayphelps

Description

@jayphelps

TypeScript Version: typescript@next

Code

Playground Link

type First<T, R> = (source: T) => R;
type Second<T> = First<T, T>;

declare function example(): Second<string>;

Expected behavior:

Using the compiler API, typeChecker.typeToString(signature.getReturnType()) of example returns the most derived alias, Second<string>

Actual behavior:

typeChecker.typeToString(signature.getReturnType()) returns First<string, string>


IntelliSense in the playground and vscode both show the same thing as typeChecker.typeToString(returnType), so I assume they share the same underlying logic.

I tried examining the type object itself to see if I could reach into private APIs to get it, but I couldn't find it. I also tried various formatting flags, but none of them seemed to give me the desired behavior.

I searched for existing issues on this, #17433 seemed similar but digging into it, I think it's different. It's also possible this behavior was intentional of course, if so, lmk. I'm using the compiler API to generate custom documentation for rxjs and there are sometimes a number of aliases used which simplify much more complex structures and hide internals.

I could try to take a crack at a patch if someone knows where I might find the applicable logic. Seems like it would need to be on the type metadata generation side, since I can't find it in the type returned from signature.getReturnType()?

Cc/ @benlesh

Metadata

Metadata

Assignees

No one assigned

    Labels

    7.0 LS MigrationBugA bug in TypeScriptDomain: LS: Type DisplayBugs relating to showing types in Quick Info/Tooltips, Signature Help, or Completion Info

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions