Skip to content
Permalink
Browse files
Rephrase error message to be 100% technically correct (#50471)
  • Loading branch information
RyanCavanaugh committed Aug 26, 2022
1 parent 71d1911 commit 3557092b1474bc3405a29da93bd15c108ab2f8b3
Show file tree
Hide file tree
Showing 50 changed files with 784 additions and 791 deletions.
@@ -34582,26 +34582,19 @@ namespace ts {
}

function tryGiveBetterPrimaryError(errNode: Node, maybeMissingAwait: boolean, leftStr: string, rightStr: string) {
let typeName: string | undefined;
switch (operatorToken.kind) {
case SyntaxKind.EqualsEqualsEqualsToken:
case SyntaxKind.EqualsEqualsToken:
typeName = "false";
break;
case SyntaxKind.ExclamationEqualsEqualsToken:
case SyntaxKind.ExclamationEqualsToken:
typeName = "true";
}

if (typeName) {
return errorAndMaybeSuggestAwait(
errNode,
maybeMissingAwait,
Diagnostics.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap,
typeName, leftStr, rightStr);
return errorAndMaybeSuggestAwait(
errNode,
maybeMissingAwait,
Diagnostics.This_comparison_appears_to_be_unintentional_because_the_types_0_and_1_have_no_overlap,
leftStr, rightStr);
default:
return undefined;
}

return undefined;
}
}

@@ -1864,7 +1864,7 @@
"category": "Error",
"code": 2366
},
"This condition will always return '{0}' since the types '{1}' and '{2}' have no overlap.": {
"This comparison appears to be unintentional because the types '{0}' and '{1}' have no overlap.": {
"category": "Error",
"code": 2367
},
@@ -13,7 +13,7 @@ namespace ts.codefix {
Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type.code,
Diagnostics.Operator_0_cannot_be_applied_to_type_1.code,
Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2.code,
Diagnostics.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap.code,
Diagnostics.This_comparison_appears_to_be_unintentional_because_the_types_0_and_1_have_no_overlap.code,
Diagnostics.This_condition_will_always_return_true_since_this_0_is_always_defined.code,
Diagnostics.Type_0_is_not_an_array_type.code,
Diagnostics.Type_0_is_not_an_array_type_or_a_string_type.code,
@@ -167,7 +167,7 @@ namespace ts.projectSystem {
);
const errorResult = session.executeCommand(getErrRequest).response as protocol.Diagnostic[];
assert.isTrue(errorResult.length === 1);
assert.equal(errorResult[0].code, Diagnostics.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap.code);
assert.equal(errorResult[0].code, Diagnostics.This_comparison_appears_to_be_unintentional_because_the_types_0_and_1_have_no_overlap.code);
});

it("should report semantic errors for configured js project with '// @ts-check' and skipLibCheck=true", () => {
@@ -194,7 +194,7 @@ namespace ts.projectSystem {
);
const errorResult = session.executeCommand(getErrRequest).response as protocol.Diagnostic[];
assert.isTrue(errorResult.length === 1);
assert.equal(errorResult[0].code, Diagnostics.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap.code);
assert.equal(errorResult[0].code, Diagnostics.This_comparison_appears_to_be_unintentional_because_the_types_0_and_1_have_no_overlap.code);
});

it("should report semantic errors for configured js project with checkJs=true and skipLibCheck=true", () => {
@@ -223,7 +223,7 @@ namespace ts.projectSystem {
);
const errorResult = session.executeCommand(getErrRequest).response as protocol.Diagnostic[];
assert.isTrue(errorResult.length === 1);
assert.equal(errorResult[0].code, Diagnostics.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap.code);
assert.equal(errorResult[0].code, Diagnostics.This_comparison_appears_to_be_unintentional_because_the_types_0_and_1_have_no_overlap.code);
});
});
}
@@ -1,5 +1,5 @@
tests/cases/compiler/capturedLetConstInLoop5.ts(174,13): error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
tests/cases/compiler/capturedLetConstInLoop5.ts(229,13): error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
tests/cases/compiler/capturedLetConstInLoop5.ts(174,13): error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
tests/cases/compiler/capturedLetConstInLoop5.ts(229,13): error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.


==== tests/cases/compiler/capturedLetConstInLoop5.ts (2 errors) ====
@@ -178,7 +178,7 @@ tests/cases/compiler/capturedLetConstInLoop5.ts(229,13): error TS2367: This cond
(() => x + v);
if (x == 1) {
~~~~~~
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
return;
}
}
@@ -235,7 +235,7 @@ tests/cases/compiler/capturedLetConstInLoop5.ts(229,13): error TS2367: This cond
(() => x + y + v);
if (x == 1) {
~~~~~~
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
return;
}
}
@@ -1,5 +1,5 @@
tests/cases/compiler/capturedLetConstInLoop5_ES6.ts(174,13): error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
tests/cases/compiler/capturedLetConstInLoop5_ES6.ts(229,13): error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
tests/cases/compiler/capturedLetConstInLoop5_ES6.ts(174,13): error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
tests/cases/compiler/capturedLetConstInLoop5_ES6.ts(229,13): error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.


==== tests/cases/compiler/capturedLetConstInLoop5_ES6.ts (2 errors) ====
@@ -178,7 +178,7 @@ tests/cases/compiler/capturedLetConstInLoop5_ES6.ts(229,13): error TS2367: This
(() => x + v);
if (x == 1) {
~~~~~~
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
return;
}
}
@@ -235,7 +235,7 @@ tests/cases/compiler/capturedLetConstInLoop5_ES6.ts(229,13): error TS2367: This
(() => x + y + v);
if (x == 1) {
~~~~~~
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
return;
}
}
@@ -1,7 +1,7 @@
tests/cases/compiler/capturedLetConstInLoop6.ts(147,9): error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
tests/cases/compiler/capturedLetConstInLoop6.ts(150,9): error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
tests/cases/compiler/capturedLetConstInLoop6.ts(194,9): error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
tests/cases/compiler/capturedLetConstInLoop6.ts(197,9): error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
tests/cases/compiler/capturedLetConstInLoop6.ts(147,9): error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
tests/cases/compiler/capturedLetConstInLoop6.ts(150,9): error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
tests/cases/compiler/capturedLetConstInLoop6.ts(194,9): error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
tests/cases/compiler/capturedLetConstInLoop6.ts(197,9): error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.


==== tests/cases/compiler/capturedLetConstInLoop6.ts (4 errors) ====
@@ -153,12 +153,12 @@ tests/cases/compiler/capturedLetConstInLoop6.ts(197,9): error TS2367: This condi
(() => x);
if (x == 1) {
~~~~~~
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
break;
}
if (x == 2) {
~~~~~~
!!! error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
continue;
}
}
@@ -204,12 +204,12 @@ tests/cases/compiler/capturedLetConstInLoop6.ts(197,9): error TS2367: This condi
(() => x + y);
if (x == 1) {
~~~~~~
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
break;
}
if (x == 2) {
~~~~~~
!!! error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
continue;
}
}
@@ -1,7 +1,7 @@
tests/cases/compiler/capturedLetConstInLoop6_ES6.ts(147,9): error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
tests/cases/compiler/capturedLetConstInLoop6_ES6.ts(150,9): error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
tests/cases/compiler/capturedLetConstInLoop6_ES6.ts(194,9): error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
tests/cases/compiler/capturedLetConstInLoop6_ES6.ts(197,9): error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
tests/cases/compiler/capturedLetConstInLoop6_ES6.ts(147,9): error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
tests/cases/compiler/capturedLetConstInLoop6_ES6.ts(150,9): error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
tests/cases/compiler/capturedLetConstInLoop6_ES6.ts(194,9): error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
tests/cases/compiler/capturedLetConstInLoop6_ES6.ts(197,9): error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.


==== tests/cases/compiler/capturedLetConstInLoop6_ES6.ts (4 errors) ====
@@ -153,12 +153,12 @@ tests/cases/compiler/capturedLetConstInLoop6_ES6.ts(197,9): error TS2367: This c
(() => x);
if (x == 1) {
~~~~~~
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
break;
}
if (x == 2) {
~~~~~~
!!! error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
continue;
}
}
@@ -204,12 +204,12 @@ tests/cases/compiler/capturedLetConstInLoop6_ES6.ts(197,9): error TS2367: This c
(() => x + y);
if (x == 1) {
~~~~~~
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
break;
}
if (x == 2) {
~~~~~~
!!! error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
continue;
}
}
@@ -1,11 +1,11 @@
tests/cases/compiler/capturedLetConstInLoop7.ts(230,9): error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
tests/cases/compiler/capturedLetConstInLoop7.ts(233,9): error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
tests/cases/compiler/capturedLetConstInLoop7.ts(236,9): error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
tests/cases/compiler/capturedLetConstInLoop7.ts(239,9): error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
tests/cases/compiler/capturedLetConstInLoop7.ts(305,9): error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
tests/cases/compiler/capturedLetConstInLoop7.ts(308,9): error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
tests/cases/compiler/capturedLetConstInLoop7.ts(311,9): error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
tests/cases/compiler/capturedLetConstInLoop7.ts(314,9): error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
tests/cases/compiler/capturedLetConstInLoop7.ts(230,9): error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
tests/cases/compiler/capturedLetConstInLoop7.ts(233,9): error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
tests/cases/compiler/capturedLetConstInLoop7.ts(236,9): error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
tests/cases/compiler/capturedLetConstInLoop7.ts(239,9): error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
tests/cases/compiler/capturedLetConstInLoop7.ts(305,9): error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
tests/cases/compiler/capturedLetConstInLoop7.ts(308,9): error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
tests/cases/compiler/capturedLetConstInLoop7.ts(311,9): error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
tests/cases/compiler/capturedLetConstInLoop7.ts(314,9): error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.


==== tests/cases/compiler/capturedLetConstInLoop7.ts (8 errors) ====
@@ -240,22 +240,22 @@ tests/cases/compiler/capturedLetConstInLoop7.ts(314,9): error TS2367: This condi
(() => x);
if (x == 1) {
~~~~~~
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
break;
}
if (x == 1) {
~~~~~~
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
break l1_c;
}
if (x == 2) {
~~~~~~
!!! error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
continue;
}
if (x == 2) {
~~~~~~
!!! error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
continue l1_c;
}
}
@@ -323,22 +323,22 @@ tests/cases/compiler/capturedLetConstInLoop7.ts(314,9): error TS2367: This condi
(() => x + y);
if (x == 1) {
~~~~~~
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
break;
}
if (x == 1) {
~~~~~~
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
break l5_c;
}
if (x == 2) {
~~~~~~
!!! error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
continue;
}
if (x == 2) {
~~~~~~
!!! error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
continue l5_c;
}
}

0 comments on commit 3557092

Please sign in to comment.