Fix error message truncation in TypeScript validator#325
Merged
Conversation
Two improvements to diagnostic message handling in createTypeScriptJsonValidator: 1. Use ts.flattenDiagnosticMessageText() instead of manually extracting d.messageText.messageText to properly handle DiagnosticMessageChain messages with nested detail. 2. For TypeScript error 2740 (missing properties truncated with "and N more"), use the type checker to reconstruct the full list of missing required properties rather than relying on the compiler's hardcoded 4-property limit. Agent-Logs-Url: https://github.com/microsoft/TypeChat/sessions/bc17d936-9d71-49f6-9fe7-d0a6d9d46770 Co-authored-by: robgruen <25374553+robgruen@users.noreply.github.com>
- Use decl.getStart(file) instead of decl.pos to exclude leading trivia from the position range check, making it more accurate - Add a JSDoc comment explaining the function's purpose and return value Agent-Logs-Url: https://github.com/microsoft/TypeChat/sessions/bc17d936-9d71-49f6-9fe7-d0a6d9d46770 Co-authored-by: robgruen <25374553+robgruen@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Investigate root cause of error message truncation in TypeScript validator
Fix error message truncation in TypeScript validator
May 4, 2026
robgruen
reviewed
May 4, 2026
TalZaccai
approved these changes
May 4, 2026
- Add test/validate.test.ts with 12 tests using node:test / node:assert:
* Valid objects passing validation (all three cases)
* Type mismatch error (backward-compat, code != 2740)
* Single missing property (TS 2741, backward-compat)
* 2-5 missing properties (TS 2739, backward-compat)
* 6+ missing required properties (TS 2740) — verifies full list with
no "and N more" truncation
* Optional properties excluded from missing-props list
* getSchemaText/getTypeName pass-through
* createModuleTextFromJson output
- Add test/tsconfig.json (compiles to out/, which is gitignored)
- Add "test" script to package.json: tsc -p test && node --test out/validate.test.js
Agent-Logs-Url: https://github.com/microsoft/TypeChat/sessions/b6e951eb-19b1-47a0-bce8-e447ac9a4efe
Co-authored-by: TalZaccai <18443527+TalZaccai@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TypeScript diagnostic code 2740 (triggered when 6+ required properties are missing) hardcodes
props.slice(0, 4)internally, producing truncated messages like:Additionally, the original code extracted only the top-level
.messageTextfrom aDiagnosticMessageChain, silently dropping any nested detail in the.nextchain.Changes (
typescript/src/ts/validate.ts)DiagnosticMessageChainhandling: Replace manuald.messageText.messageTextextraction withts.flattenDiagnosticMessageText(d.messageText, "\n"), which correctly traverses the full chain.expandMissingPropertiesMessagehelper: For diagnostic code 2740, usesprogram.getTypeChecker()to reconstruct the complete missing-property list. Locates the exact variable declaration viadecl.getStart(file) <= d.start <= decl.end, filters optional symbols (ts.SymbolFlags.Optional), and formats withts.TypeFormatFlags.NoTruncation. Falls back to the original compiler message if expansion fails.Note:
noErrorTruncationcompiler option does not address this — it only affects type name length, not the property list count.Tests (
typescript/test/validate.test.ts)Added 12 unit tests using Node.js's built-in
node:test/node:assert(no new dependencies), runnable vianpm test. The tests verify:"and N more"truncation