TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Compiler Option typeTruncationLength

Open HardworkingSlacker opened this issue 1 year ago • 3 comments

🔍 Search Terms

"type truncation truncate compiler option "

✅ Viability Checklist

  • [X] This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • [X] This wouldn't change the runtime behavior of existing JavaScript code
  • [X] This could be implemented without emitting different JS based on the types of the expressions
  • [X] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • [X] This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
  • [X] This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals

⭐ Suggestion

New Compiler Option for tsconfig: typeTruncationLength: number The specified number is the amount of characters that will be shown before an ellipsis cutoff happens. set to 1600 characters by default. special value 0 means truncation is disabled completely.

📃 Motivating Example

I need type information to know what I am working with, especially when working with mapped or infered Types. Preferably, I hover over the type or variable I want to inspect in visual studio code (or typescript playground). This information inevitably gets truncated when it exceeds the built-in character limit of effectively 1600, even when setting noErrorTruncation to true (which shouldn't affect type information yet it does, see #26238) You can manually adjust that limit by hacking tsserver.js in your vscode install location (reference).

I think that being able to receive complete type information in a language that's entire purpose is to add said thing to javascript is a core requirement.

This code example might help exemplify the issue (switch noErrorTruncation on/off to see the different behaviors for onhover truncation).

💻 Use Cases

  1. What do you want to use this for? The ability to see complete type information even for very complex or long types
  2. What shortcomings exist with current approaches? Partial information entails extensive backtracking to the original interfaces/type definitions to see all fields and their types or intentionally causing type errors to see full information.
  3. What workarounds are you using in the meantime? The aforementioned hack.

HardworkingSlacker avatar Jun 26 '24 10:06 HardworkingSlacker

We have a separate issue tracking better interactivity with tooltips, which might subsume any use cases here

RyanCavanaugh avatar Jul 26 '24 21:07 RyanCavanaugh

Thank you for your answer but would you mind referencing the issue you were talking about? I couldn't pinpoint it based on search results.

HardworkingSlacker avatar Jul 30 '24 10:07 HardworkingSlacker

Also see https://stackoverflow.com/a/78690276: work-around is change the value of the defaultMaximumTruncationLength variable in typescript.js of your local typescript install to a higher number

Works great, but sucks to have to edit the library in every project and on every upgrade

p-bakker avatar Jun 18 '25 15:06 p-bakker

Would be nice to have this configurable

insilications avatar Jul 09 '25 10:07 insilications

Any update?

paul-uz avatar Sep 23 '25 14:09 paul-uz