From 85cbc66028b50e6e432cd4723c13a998e0317ce5 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 5 Feb 2019 16:20:04 -0800 Subject: [PATCH] Don't chain diagnostics after excess property messages have been issued. --- src/compiler/checker.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 23459491518..3cb197cfec3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11886,6 +11886,11 @@ namespace ts { let expandingFlags = ExpandingFlags.None; let overflow = false; let suppressNextError = false; + // Ordinarily, we want to construct "breadcrumbs" at each level as we dive into types + // so that the user can build up the same context that the relationship checker had and + // diagnose issues. However, sometimes this trail becomes noise when the deepest elabration + // is already so specific and obvious. In some cases, we want to just bubble up a single diagnostic. + let shouldConstructDiagnosticTrail = true; Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking"); @@ -11928,7 +11933,9 @@ namespace ts { function reportError(message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number, arg3?: string | number): void { Debug.assert(!!errorNode); - errorInfo = chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2, arg3); + if (shouldConstructDiagnosticTrail) { + errorInfo = chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2, arg3); + } } function associateRelatedInfo(info: DiagnosticRelatedInformation) { @@ -12243,6 +12250,7 @@ namespace ts { reportError(Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(errorTarget)); } + shouldConstructDiagnosticTrail = false; } } return true;