Skip to content

Commit 3557092

Browse files
Rephrase error message to be 100% technically correct (#50471)
1 parent 71d1911 commit 3557092

File tree

50 files changed

+784
-791
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+784
-791
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34582,26 +34582,19 @@ namespace ts {
3458234582
}
3458334583

3458434584
function tryGiveBetterPrimaryError(errNode: Node, maybeMissingAwait: boolean, leftStr: string, rightStr: string) {
34585-
let typeName: string | undefined;
3458634585
switch (operatorToken.kind) {
3458734586
case SyntaxKind.EqualsEqualsEqualsToken:
3458834587
case SyntaxKind.EqualsEqualsToken:
34589-
typeName = "false";
34590-
break;
3459134588
case SyntaxKind.ExclamationEqualsEqualsToken:
3459234589
case SyntaxKind.ExclamationEqualsToken:
34593-
typeName = "true";
34594-
}
34595-
34596-
if (typeName) {
34597-
return errorAndMaybeSuggestAwait(
34598-
errNode,
34599-
maybeMissingAwait,
34600-
Diagnostics.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap,
34601-
typeName, leftStr, rightStr);
34590+
return errorAndMaybeSuggestAwait(
34591+
errNode,
34592+
maybeMissingAwait,
34593+
Diagnostics.This_comparison_appears_to_be_unintentional_because_the_types_0_and_1_have_no_overlap,
34594+
leftStr, rightStr);
34595+
default:
34596+
return undefined;
3460234597
}
34603-
34604-
return undefined;
3460534598
}
3460634599
}
3460734600

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1864,7 +1864,7 @@
18641864
"category": "Error",
18651865
"code": 2366
18661866
},
1867-
"This condition will always return '{0}' since the types '{1}' and '{2}' have no overlap.": {
1867+
"This comparison appears to be unintentional because the types '{0}' and '{1}' have no overlap.": {
18681868
"category": "Error",
18691869
"code": 2367
18701870
},

src/services/codefixes/addMissingAwait.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace ts.codefix {
1313
Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type.code,
1414
Diagnostics.Operator_0_cannot_be_applied_to_type_1.code,
1515
Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2.code,
16-
Diagnostics.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap.code,
16+
Diagnostics.This_comparison_appears_to_be_unintentional_because_the_types_0_and_1_have_no_overlap.code,
1717
Diagnostics.This_condition_will_always_return_true_since_this_0_is_always_defined.code,
1818
Diagnostics.Type_0_is_not_an_array_type.code,
1919
Diagnostics.Type_0_is_not_an_array_type_or_a_string_type.code,

src/testRunner/unittests/tsserver/skipLibCheck.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ namespace ts.projectSystem {
167167
);
168168
const errorResult = session.executeCommand(getErrRequest).response as protocol.Diagnostic[];
169169
assert.isTrue(errorResult.length === 1);
170-
assert.equal(errorResult[0].code, Diagnostics.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap.code);
170+
assert.equal(errorResult[0].code, Diagnostics.This_comparison_appears_to_be_unintentional_because_the_types_0_and_1_have_no_overlap.code);
171171
});
172172

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

200200
it("should report semantic errors for configured js project with checkJs=true and skipLibCheck=true", () => {
@@ -223,7 +223,7 @@ namespace ts.projectSystem {
223223
);
224224
const errorResult = session.executeCommand(getErrRequest).response as protocol.Diagnostic[];
225225
assert.isTrue(errorResult.length === 1);
226-
assert.equal(errorResult[0].code, Diagnostics.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap.code);
226+
assert.equal(errorResult[0].code, Diagnostics.This_comparison_appears_to_be_unintentional_because_the_types_0_and_1_have_no_overlap.code);
227227
});
228228
});
229229
}

tests/baselines/reference/capturedLetConstInLoop5.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
tests/cases/compiler/capturedLetConstInLoop5.ts(174,13): error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
2-
tests/cases/compiler/capturedLetConstInLoop5.ts(229,13): error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
1+
tests/cases/compiler/capturedLetConstInLoop5.ts(174,13): error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
2+
tests/cases/compiler/capturedLetConstInLoop5.ts(229,13): error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
33

44

55
==== tests/cases/compiler/capturedLetConstInLoop5.ts (2 errors) ====
@@ -178,7 +178,7 @@ tests/cases/compiler/capturedLetConstInLoop5.ts(229,13): error TS2367: This cond
178178
(() => x + v);
179179
if (x == 1) {
180180
~~~~~~
181-
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
181+
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
182182
return;
183183
}
184184
}
@@ -235,7 +235,7 @@ tests/cases/compiler/capturedLetConstInLoop5.ts(229,13): error TS2367: This cond
235235
(() => x + y + v);
236236
if (x == 1) {
237237
~~~~~~
238-
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
238+
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
239239
return;
240240
}
241241
}

tests/baselines/reference/capturedLetConstInLoop5_ES6.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
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.
2-
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.
1+
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.
2+
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.
33

44

55
==== tests/cases/compiler/capturedLetConstInLoop5_ES6.ts (2 errors) ====
@@ -178,7 +178,7 @@ tests/cases/compiler/capturedLetConstInLoop5_ES6.ts(229,13): error TS2367: This
178178
(() => x + v);
179179
if (x == 1) {
180180
~~~~~~
181-
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
181+
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
182182
return;
183183
}
184184
}
@@ -235,7 +235,7 @@ tests/cases/compiler/capturedLetConstInLoop5_ES6.ts(229,13): error TS2367: This
235235
(() => x + y + v);
236236
if (x == 1) {
237237
~~~~~~
238-
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
238+
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
239239
return;
240240
}
241241
}

tests/baselines/reference/capturedLetConstInLoop6.errors.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
tests/cases/compiler/capturedLetConstInLoop6.ts(147,9): error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
2-
tests/cases/compiler/capturedLetConstInLoop6.ts(150,9): error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
3-
tests/cases/compiler/capturedLetConstInLoop6.ts(194,9): error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
4-
tests/cases/compiler/capturedLetConstInLoop6.ts(197,9): error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
1+
tests/cases/compiler/capturedLetConstInLoop6.ts(147,9): error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
2+
tests/cases/compiler/capturedLetConstInLoop6.ts(150,9): error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
3+
tests/cases/compiler/capturedLetConstInLoop6.ts(194,9): error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
4+
tests/cases/compiler/capturedLetConstInLoop6.ts(197,9): error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
55

66

77
==== tests/cases/compiler/capturedLetConstInLoop6.ts (4 errors) ====
@@ -153,12 +153,12 @@ tests/cases/compiler/capturedLetConstInLoop6.ts(197,9): error TS2367: This condi
153153
(() => x);
154154
if (x == 1) {
155155
~~~~~~
156-
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
156+
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
157157
break;
158158
}
159159
if (x == 2) {
160160
~~~~~~
161-
!!! error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
161+
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
162162
continue;
163163
}
164164
}
@@ -204,12 +204,12 @@ tests/cases/compiler/capturedLetConstInLoop6.ts(197,9): error TS2367: This condi
204204
(() => x + y);
205205
if (x == 1) {
206206
~~~~~~
207-
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
207+
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
208208
break;
209209
}
210210
if (x == 2) {
211211
~~~~~~
212-
!!! error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
212+
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
213213
continue;
214214
}
215215
}

tests/baselines/reference/capturedLetConstInLoop6_ES6.errors.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
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.
2-
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.
3-
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.
4-
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.
1+
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.
2+
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.
3+
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.
4+
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.
55

66

77
==== tests/cases/compiler/capturedLetConstInLoop6_ES6.ts (4 errors) ====
@@ -153,12 +153,12 @@ tests/cases/compiler/capturedLetConstInLoop6_ES6.ts(197,9): error TS2367: This c
153153
(() => x);
154154
if (x == 1) {
155155
~~~~~~
156-
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
156+
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
157157
break;
158158
}
159159
if (x == 2) {
160160
~~~~~~
161-
!!! error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
161+
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
162162
continue;
163163
}
164164
}
@@ -204,12 +204,12 @@ tests/cases/compiler/capturedLetConstInLoop6_ES6.ts(197,9): error TS2367: This c
204204
(() => x + y);
205205
if (x == 1) {
206206
~~~~~~
207-
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
207+
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
208208
break;
209209
}
210210
if (x == 2) {
211211
~~~~~~
212-
!!! error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
212+
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
213213
continue;
214214
}
215215
}

tests/baselines/reference/capturedLetConstInLoop7.errors.txt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
tests/cases/compiler/capturedLetConstInLoop7.ts(230,9): error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
2-
tests/cases/compiler/capturedLetConstInLoop7.ts(233,9): error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
3-
tests/cases/compiler/capturedLetConstInLoop7.ts(236,9): error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
4-
tests/cases/compiler/capturedLetConstInLoop7.ts(239,9): error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
5-
tests/cases/compiler/capturedLetConstInLoop7.ts(305,9): error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
6-
tests/cases/compiler/capturedLetConstInLoop7.ts(308,9): error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
7-
tests/cases/compiler/capturedLetConstInLoop7.ts(311,9): error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
8-
tests/cases/compiler/capturedLetConstInLoop7.ts(314,9): error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
1+
tests/cases/compiler/capturedLetConstInLoop7.ts(230,9): error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
2+
tests/cases/compiler/capturedLetConstInLoop7.ts(233,9): error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
3+
tests/cases/compiler/capturedLetConstInLoop7.ts(236,9): error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
4+
tests/cases/compiler/capturedLetConstInLoop7.ts(239,9): error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
5+
tests/cases/compiler/capturedLetConstInLoop7.ts(305,9): error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
6+
tests/cases/compiler/capturedLetConstInLoop7.ts(308,9): error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
7+
tests/cases/compiler/capturedLetConstInLoop7.ts(311,9): error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
8+
tests/cases/compiler/capturedLetConstInLoop7.ts(314,9): error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
99

1010

1111
==== tests/cases/compiler/capturedLetConstInLoop7.ts (8 errors) ====
@@ -240,22 +240,22 @@ tests/cases/compiler/capturedLetConstInLoop7.ts(314,9): error TS2367: This condi
240240
(() => x);
241241
if (x == 1) {
242242
~~~~~~
243-
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
243+
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
244244
break;
245245
}
246246
if (x == 1) {
247247
~~~~~~
248-
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
248+
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
249249
break l1_c;
250250
}
251251
if (x == 2) {
252252
~~~~~~
253-
!!! error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
253+
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
254254
continue;
255255
}
256256
if (x == 2) {
257257
~~~~~~
258-
!!! error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
258+
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
259259
continue l1_c;
260260
}
261261
}
@@ -323,22 +323,22 @@ tests/cases/compiler/capturedLetConstInLoop7.ts(314,9): error TS2367: This condi
323323
(() => x + y);
324324
if (x == 1) {
325325
~~~~~~
326-
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
326+
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
327327
break;
328328
}
329329
if (x == 1) {
330330
~~~~~~
331-
!!! error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap.
331+
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '1' have no overlap.
332332
break l5_c;
333333
}
334334
if (x == 2) {
335335
~~~~~~
336-
!!! error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
336+
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
337337
continue;
338338
}
339339
if (x == 2) {
340340
~~~~~~
341-
!!! error TS2367: This condition will always return 'false' since the types '0' and '2' have no overlap.
341+
!!! error TS2367: This comparison appears to be unintentional because the types '0' and '2' have no overlap.
342342
continue l5_c;
343343
}
344344
}

0 commit comments

Comments
 (0)