TypeScript: Setting noErrorTruncation to false truncates inferred type of variables/functions; which are not errors
TypeScript Version: 3.0.1
Search Terms: noErrorTruncation
In TS 2.9, if noErrorTruncation is unset, or set to false, hovering the cursor over an identifier for type inference in VS code would bring up a tooltip with the inferred type.
In TS 3.0, if noErrorTruncation is unset, or set to false, the tooltip with the inferred type will be truncated with ellipsis.
Code
TS 2.9, with noErrorTruncation : false
/*snip*/
__canAccept: {
page?: string | number | null | undefined;
itemsPerPage?: string | number | null | undefined;
};
}
TS 3.0 with noErrorTruncation : false
/*snip*/
__canAccept: {
...;
};
}
Expected behavior:
noErrorTruncation is about truncating errors.
The tooltips displaying inferred types aren’t errors, and should not be affected by this flag.
Actual behavior:
noErrorTruncation affects tooltips displaying inferred types.
If anyone else is having this problem, just go to your tsconfig.json, add the following line,
"noErrorTruncation": true,
and restart VS code (or your editor of choice)
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 73
- Comments: 27 (3 by maintainers)
Having this problem as well. Investigating and debugging this issue led me to find this being introduced in merge https://github.com/microsoft/TypeScript/pull/24258.
Typescript starts truncating the output when it reaches the default hard-limit of
160 * 10characters to prevent the server from hanging too long, even with"noErrorTruncation": trueset. There’s currently no option for VS Code to disable it from the looks of it: https://github.com/microsoft/TypeScript/blob/57e2fe0462bb897e581aa489f1d6040db559d82b/src/services/utilities.ts#L1993For people using VS Code, a quick fix would be opening
<Microsoft VS Code install folder>/resources/app/extensions/node_modules/typescript/lib/tsserver.jsand changets.defaultMaximumTruncationLength = 160at around line 12797 to something higher likets.defaultMaximumTruncationLength = 800.It’s not just CI, it’s usability problem. I actually like browsing (and copying) the type from the hover tip in the VSCode, and when it gets truncated it’s pretty much useless.
Weird. I thought I finally “fixed” it but, even with
noErrorTruncationturned on, some long and complicated types still show up with ellipsis.Is there a
noInferredTypeTruncationthing I’m missing?Turning on
noErrorTruncationcertainly stops some truncations, but it still doesn’t prevent others.Yes agree here, it would be huge to at least have some tool - perhaps even something dedicated that would allow us to see the fully expanded and normalized type that typescript will use. Perhaps a custom “peek” style popup for it so that we can choose to view it only when we need to in the case of large types that would make processing type extreme.
@xbtsw Using
"noErrorTruncation": trueworks perfectly on my end. (typescript v3.4.3)edit: Something like
noInferredTypeTruncationwould be great! 👍The hack is good to know about, but it isn’t really a solution for me. What I’m running into is that I often want to hover a type and want see the entire type (no “…”), but when I’m trying to read an error, showing entire type definitions can sometimes make the error utterly unreadable. So, some finer grained control is really needed here. Ideally, there’d be some integration between TypeScript and VSCode to provide a toggle to choose between “verbose” (types expanded) and “compact” (types truncated).
The ellipses makes it very hard to debug Pick, Omit, etc, when things went wrong.
There is one awesome extension that is just enormously cool. It allows to explore “compiled” versions of very complex types
It allows to explore not only types and interfaces, but literally anything: vars, functions, classes, promises, generics
Name: TypeScript Explorer Id: mxsdev.typescript-explorer Description: Full type information for variables, components, functions, and more in TypeScript projects! Version: 0.4.0 Publisher: mxs VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=mxsdev.typescript-explorer
Thanks again for the hack!
I just wanted to call out that if your VSCode config specifies the
"typescript.tsdk"option, you’ll need to update thetsserver.tsin whatever location that option specifies. It would have saved me a bit of debugging time 🙃one solution (that are not fast on the project that i works, because needs to load a bunch of things, but works very well) is the extension ts type expand.
https://github.com/d-kimuson/ts-type-expand
Make this vscode feature please - it’s annoying to configure manually.
The ellipsis makes it especially difficult to debug type issues (not type errors) involving
Pick,Omitetc.For example in a type that involves
OmitI made a typo in second parameter ofOmit, then in some other place I wondered why a interface property is still accepted. The ellipsis makes it difficult to trace back and find the original typo.Thank you for your efforts sleuthing this out @Hati- !
I would hope to see this value bound as a configurable TS preference. However it is awesome to know that there is a way to hack around the limitation.
This is awesome @Zetxus - thanks so much!
For me, the path name has spaces in it which was upsetting the sed command (I couldn’t work out why), so with the help of chatGPT I managed to refactor it to use awk. Sharing here for others:
Thank you for saying this because you saved me a lot of time! Slight correction, though: it’s named
tsserver.jsIf for nothing else, I thought this was worth reporting for the irony: in my case, the
...was truncating a three character number.@vensauro That extension doesn’t seem to work anymore. Shame, because it looks really useful.
noErrorTruncationalso does not solve this problem for me.Thanks for the hack @Hati-, Another gotcha I found is that if you’re using VSCode on the WSL2, your tsserver.js is located here:
~/.vscode-server/bin/*SOME_HASH_HERE*/extensions/node_modules/typescript/lib/tsserver.jsHere’s a quick bash script I use to quickly switch back and forth to avoid any performance issues with high values on the truncation:
Executing it with just the dir will result in resetting it to the default value of 160:
Executing it with a second argument will change it
Note: restarting the TS server is enough for the changes to take effect, no need to restart the entire VSCode.