How to see a fully-expanded TypeScript type without "N more" and "..."?
Asked Answered
O

3

79

In VSCode, TypeScript shows really useful expansions of types I define. But there's a limit to what TS will show in IntelliSense. If a type is too long, then I'll see output like this:

enter image description here

Note the "11 more" near the end. Sometimes, for troubleshooting a difficult type definition, it's really helpful to see what's in that "N more" section.

Is there a way to get ahold of (for troubleshooting purposes during development) the fully-expanded type definition, without those "N more" messages to hide what's inside?

https://github.com/Microsoft/vscode/issues/6638 implies that this capability might not have been available (nor planned) as of Feb 2017, but I'm not sure I'm reading that issue correctly and regardless things may have changed in the meantime.

Orfurd answered 2/11, 2018 at 5:19 Comment(0)
S
91

Try setting the noErrorTruncation option to true in tsconfig.json. Confusingly enough, this option affects truncation of types displayed on hover in at least some circumstances; see this issue. Be careful: if your type is really huge, VS Code may hang when you try to view it.

Sandblind answered 3/11, 2018 at 13:31 Comment(4)
Unfortunately as mentioned in the issue linked this only seems to remove "..." in some cases and not allGert
@Gert This GitHub comment shows a workaround for those cases: github.com/microsoft/TypeScript/issues/… To quote: "For people using VS Code, a quick fix would be opening <Microsoft VS Code install folder>/resources/app/extensions/node_modules/typescript/lib/tsserver.js and change ts.defaultMaximumTruncationLength = 160 at around line 12797 to something higher like ts.defaultMaximumTruncationLength = 800."Glycogen
for clarity, set the option as follows: { "compilerOptions": { "noErrorTruncation": true, } }Vampirism
the typescript-explorer extension is probably the better answer - github.com/Microsoft/TypeScript/issues/…Transom
G
24

The accepted answer works for cases where the length of the type's description is 1600 characters or less.

To go beyond this hard limit, it's necessary to tweak the source code, as described in this fix posted on GitHub.

To quote:

For people using VS Code, a quick fix would be opening <Microsoft VS Code install folder>/resources/app/extensions/node_modules/typescript/lib/tsserver.js and change ts.defaultMaximumTruncationLength = 160 at around line 12797 to something higher like ts.defaultMaximumTruncationLength = 800.

Once you've made the change, close and restart VSCode to get the intended effect.

(The new hard limit will be 10 * whatever value you set.)

Glycogen answered 29/5, 2021 at 0:30 Comment(1)
FYI: when the change is made, you can just reload the VSCode window using (in MacOs) command + P and then > Developer: Reload WindowIeper
B
4

In the next line you can write:

type SubType = TransformArray['']

Put cursor inside the '' and VS-Code should display more helpful popover.

Bambara answered 28/6, 2022 at 20:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.