Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 415
Justin Grant Avatar asked Nov 02 '18 05:11

Justin Grant


People also ask

Does TypeScript have IntelliSense?

Visual Studio Code IntelliSense is provided for JavaScript, TypeScript, JSON, HTML, CSS, SCSS, and Less out of the box. VS Code supports word based completions for any programming language but can also be configured to have richer IntelliSense by installing a language extension.

What is TypeScript IntelliSense?

IntelliSense shows you intelligent code completion, hover information, and signature help so that you can write code more quickly and correctly. VS Code provides IntelliSense for individual TypeScript files as well as TypeScript tsconfig. json projects.

How can I tell what version of TypeScript VS Code?

The -g means it's installed on your system globally so that the TypeScript compiler can be used in any of your projects. Test that the TypeScript is installed correctly by typing tsc -v into your terminal or command prompt. You should see the TypeScript version print out to the screen.


2 Answers

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.

like image 110
Matt McCutchen Avatar answered Oct 24 '22 03:10

Matt McCutchen


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.)

like image 39
Mattias Martens Avatar answered Oct 24 '22 02:10

Mattias Martens