How to extract a large type with vs-code without the '... 19 more ...' truncate?

Viewed 232

I have a large object (pvtMsg). vs-code shows a popup with the type when you hover over it. I would like to copy the entire type and paste it in another file. Then I would import that file in places where I want to use that type.

screenshot of vs-code with large typescript object with a hover popup of the implicit type.

The text is selectable, but the type is not complete, when I copy the text with ctrl + a the text ... 19 more ... is copied. Is there a setting in vs-code to increase the maximum length before truncation?

screenshot of the incomplete implicit type

This issue also occures with javascript or .js files.

1 Answers

It might sound unintuitive, but the noErrorTruncation compiler option does not only control error messages, but also toggles truncation of type hints. If you set it to true in your tsconfig.json (or pass the equivalent CLI option), you will notice that the hints are no longer truncated.

For example, let's make an object Test with 35 properties. Here's how the hint looks like with noErrorTruncation: false:

truncated type hint for an object with 35 properties

And here is how it looks like with noErrorTruncation: true:

full type hint for an object with 35 properties

Playground

Note that there is a hard-coded absoluteMaximumLength cutoff (calculated from defaultMaximumTruncationLength to a total of 1600 chars ATTOW) at which point the display will be truncated regardless of whether the option is enabled or not.

Related