microsoft / microsoft/TypeScript
Compiler Option typeTruncationLength
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔍 Search Terms
"type truncation truncate compiler option "
✅ Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- 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
- What do you want to use this for? The ability to see complete type information even for very complex or long types
- 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.
- What workarounds are you using in the meantime? The aforementioned hack.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the issue's description of noErrorTruncation, the tsserver.js workaround, and the linked TypeScript Playground example to understand the differing hover behavior. Trace where the proposed tsconfig option would apply across compiler and language-service output, then define tests for the default limit, a custom character count, and 0 disabling truncation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100