Skip to content

Commit cc3a49e

Browse files
committed
Fix error message regressed by microsoft#30916
1 parent 6c4876a commit cc3a49e

6 files changed

+48
-4
lines changed

src/compiler/checker.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12302,7 +12302,7 @@ namespace ts {
1230212302
let depth = 0;
1230312303
let expandingFlags = ExpandingFlags.None;
1230412304
let overflow = false;
12305-
let suppressNextError = false;
12305+
let overrideNextErrorInfo: DiagnosticMessageChain | undefined;
1230612306

1230712307
Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
1230812308

@@ -12589,10 +12589,14 @@ namespace ts {
1258912589
}
1259012590

1259112591
if (!result && reportErrors) {
12592-
const maybeSuppress = suppressNextError;
12593-
suppressNextError = false;
12592+
let maybeSuppress = overrideNextErrorInfo;
12593+
overrideNextErrorInfo = undefined;
1259412594
if (source.flags & TypeFlags.Object && target.flags & TypeFlags.Object) {
12595+
const currentError = errorInfo;
1259512596
tryElaborateArrayLikeErrors(source, target, reportErrors);
12597+
if (errorInfo !== currentError) {
12598+
maybeSuppress = errorInfo;
12599+
}
1259612600
}
1259712601
if (source.flags & TypeFlags.Object && target.flags & TypeFlags.Primitive) {
1259812602
tryElaborateErrorsForPrimitivesAndObjects(source, target);
@@ -13524,16 +13528,20 @@ namespace ts {
1352413528
if (unmatchedProperty) {
1352513529
if (reportErrors) {
1352613530
const props = arrayFrom(getUnmatchedProperties(source, target, requireOptionalProperties, /*matchDiscriminantProperties*/ false));
13531+
let shouldSkipElaboration = false;
1352713532
if (!headMessage || (headMessage.code !== Diagnostics.Class_0_incorrectly_implements_interface_1.code &&
1352813533
headMessage.code !== Diagnostics.Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass.code)) {
13529-
suppressNextError = true; // Retain top-level error for interface implementing issues, otherwise omit it
13534+
shouldSkipElaboration = true; // Retain top-level error for interface implementing issues, otherwise omit it
1353013535
}
1353113536
if (props.length === 1) {
1353213537
const propName = symbolToString(unmatchedProperty);
1353313538
reportError(Diagnostics.Property_0_is_missing_in_type_1_but_required_in_type_2, propName, ...getTypeNamesForErrorDisplay(source, target));
1353413539
if (length(unmatchedProperty.declarations)) {
1353513540
associateRelatedInfo(createDiagnosticForNode(unmatchedProperty.declarations[0], Diagnostics._0_is_declared_here, propName));
1353613541
}
13542+
if (shouldSkipElaboration) {
13543+
overrideNextErrorInfo = errorInfo;
13544+
}
1353713545
}
1353813546
else if (tryElaborateArrayLikeErrors(source, target, /*reportErrors*/ false)) {
1353913547
if (props.length > 5) { // arbitrary cutoff for too-long list form
@@ -13542,7 +13550,11 @@ namespace ts {
1354213550
else {
1354313551
reportError(Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2, typeToString(source), typeToString(target), map(props, p => symbolToString(p)).join(", "));
1354413552
}
13553+
if (shouldSkipElaboration) {
13554+
overrideNextErrorInfo = errorInfo;
13555+
}
1354513556
}
13557+
// ELSE: No array like or unmatched property error - just issue top level error (errorInfo = undefined)
1354613558
}
1354713559
return Ternary.False;
1354813560
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
tests/cases/compiler/assigningFunctionToTupleIssuesError.ts(2,5): error TS2322: Type '() => void' is not assignable to type '[string]'.
2+
3+
4+
==== tests/cases/compiler/assigningFunctionToTupleIssuesError.ts (1 errors) ====
5+
declare let a: () => void;
6+
let b: [string] = a;
7+
~
8+
!!! error TS2322: Type '() => void' is not assignable to type '[string]'.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [assigningFunctionToTupleIssuesError.ts]
2+
declare let a: () => void;
3+
let b: [string] = a;
4+
5+
//// [assigningFunctionToTupleIssuesError.js]
6+
var b = a;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/assigningFunctionToTupleIssuesError.ts ===
2+
declare let a: () => void;
3+
>a : Symbol(a, Decl(assigningFunctionToTupleIssuesError.ts, 0, 11))
4+
5+
let b: [string] = a;
6+
>b : Symbol(b, Decl(assigningFunctionToTupleIssuesError.ts, 1, 3))
7+
>a : Symbol(a, Decl(assigningFunctionToTupleIssuesError.ts, 0, 11))
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/assigningFunctionToTupleIssuesError.ts ===
2+
declare let a: () => void;
3+
>a : () => void
4+
5+
let b: [string] = a;
6+
>b : [string]
7+
>a : () => void
8+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare let a: () => void;
2+
let b: [string] = a;

0 commit comments

Comments
 (0)