diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e1262879ba3b2..1ae727fc755ca 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -34680,8 +34680,8 @@ namespace ts { errorAndMaybeSuggestAwait( condExpr, /*maybeMissingAwait*/ true, - Diagnostics.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap, - "true", getTypeNameForErrorDisplay(type), "false"); + Diagnostics.This_condition_will_always_return_true_since_this_0_appears_to_always_be_defined, + getTypeNameForErrorDisplay(type)); return; } @@ -34714,7 +34714,7 @@ namespace ts { const isUsed = isBinaryExpression(condExpr.parent) && isFunctionUsedInBinaryExpressionChain(condExpr.parent, testedSymbol) || body && isFunctionUsedInConditionBody(condExpr, body, testedNode, testedSymbol); if (!isUsed) { - error(location, Diagnostics.This_condition_will_always_return_true_since_the_function_is_always_defined_Did_you_mean_to_call_it_instead); + error(location, Diagnostics.This_condition_will_always_return_true_since_this_function_appears_to_always_be_defined_Did_you_mean_to_call_it_instead); } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b23bfbf7ea423..71ec0bd2fcc9d 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3148,7 +3148,7 @@ "category": "Error", "code": 2773 }, - "This condition will always return true since the function is always defined. Did you mean to call it instead?": { + "This condition will always return true since this function appears to always be defined. Did you mean to call it instead?": { "category": "Error", "code": 2774 }, @@ -3256,7 +3256,7 @@ "category": "Error", "code": 2800 }, - "This condition will always return true since the Promise is always truthy.": { + "This condition will always return true since this '{0}' appears to always be defined.": { "category": "Error", "code": 2801 }, diff --git a/src/services/codefixes/addMissingAwait.ts b/src/services/codefixes/addMissingAwait.ts index 1b16a33deb382..a31bf50f46ea3 100644 --- a/src/services/codefixes/addMissingAwait.ts +++ b/src/services/codefixes/addMissingAwait.ts @@ -14,6 +14,7 @@ namespace ts.codefix { 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_condition_will_always_return_true_since_this_0_appears_to_always_be_defined.code, Diagnostics.Type_0_is_not_an_array_type.code, Diagnostics.Type_0_is_not_an_array_type_or_a_string_type.code, Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators.code, diff --git a/src/services/codefixes/fixMissingCallParentheses.ts b/src/services/codefixes/fixMissingCallParentheses.ts index a144bc40f5045..042f7b506c7d5 100644 --- a/src/services/codefixes/fixMissingCallParentheses.ts +++ b/src/services/codefixes/fixMissingCallParentheses.ts @@ -2,7 +2,7 @@ namespace ts.codefix { const fixId = "fixMissingCallParentheses"; const errorCodes = [ - Diagnostics.This_condition_will_always_return_true_since_the_function_is_always_defined_Did_you_mean_to_call_it_instead.code, + Diagnostics.This_condition_will_always_return_true_since_this_function_appears_to_always_be_defined_Did_you_mean_to_call_it_instead.code, ]; registerCodeFix({ diff --git a/tests/baselines/reference/truthinessCallExpressionCoercion.errors.txt b/tests/baselines/reference/truthinessCallExpressionCoercion.errors.txt index 0e0b2c984041e..132738e4ac1fe 100644 --- a/tests/baselines/reference/truthinessCallExpressionCoercion.errors.txt +++ b/tests/baselines/reference/truthinessCallExpressionCoercion.errors.txt @@ -1,17 +1,17 @@ -tests/cases/compiler/truthinessCallExpressionCoercion.ts(2,9): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? -tests/cases/compiler/truthinessCallExpressionCoercion.ts(18,9): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? -tests/cases/compiler/truthinessCallExpressionCoercion.ts(36,9): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? -tests/cases/compiler/truthinessCallExpressionCoercion.ts(50,9): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? -tests/cases/compiler/truthinessCallExpressionCoercion.ts(66,13): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? -tests/cases/compiler/truthinessCallExpressionCoercion.ts(76,9): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? -tests/cases/compiler/truthinessCallExpressionCoercion.ts(82,9): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion.ts(2,9): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion.ts(18,9): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion.ts(36,9): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion.ts(50,9): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion.ts(66,13): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion.ts(76,9): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion.ts(82,9): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? ==== tests/cases/compiler/truthinessCallExpressionCoercion.ts (7 errors) ==== function onlyErrorsWhenTestingNonNullableFunctionType(required: () => boolean, optional?: () => boolean) { if (required) { // error ~~~~~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? } if (optional) { // ok @@ -29,7 +29,7 @@ tests/cases/compiler/truthinessCallExpressionCoercion.ts(82,9): error TS2774: Th if (test) { // error ~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? console.log('test'); } @@ -49,7 +49,7 @@ tests/cases/compiler/truthinessCallExpressionCoercion.ts(82,9): error TS2774: Th if (test) { // error ~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? [() => null].forEach(test => { test(); }); @@ -65,7 +65,7 @@ tests/cases/compiler/truthinessCallExpressionCoercion.ts(82,9): error TS2774: Th if (x.foo.bar) { // error ~~~~~~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? } if (x.foo.bar) { // ok @@ -83,7 +83,7 @@ tests/cases/compiler/truthinessCallExpressionCoercion.ts(82,9): error TS2774: Th test() { if (this.isUser) { // error ~~~~~~~~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? } if (this.maybeIsUser) { // ok @@ -95,7 +95,7 @@ tests/cases/compiler/truthinessCallExpressionCoercion.ts(82,9): error TS2774: Th function A(stats: StatsBase) { if (stats.isDirectory) { // err ~~~~~~~~~~~~~~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? console.log(`[Directory] ${stats.ctime}`) } } @@ -103,7 +103,7 @@ tests/cases/compiler/truthinessCallExpressionCoercion.ts(82,9): error TS2774: Th function B(a: Nested, b: Nested) { if (a.stats.isDirectory) { // err ~~~~~~~~~~~~~~~~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? b.stats.isDirectory(); } if (a.stats.isDirectory) { // ok diff --git a/tests/baselines/reference/truthinessCallExpressionCoercion1.errors.txt b/tests/baselines/reference/truthinessCallExpressionCoercion1.errors.txt index ed7ba0a570973..4c041935cde8f 100644 --- a/tests/baselines/reference/truthinessCallExpressionCoercion1.errors.txt +++ b/tests/baselines/reference/truthinessCallExpressionCoercion1.errors.txt @@ -1,8 +1,8 @@ -tests/cases/compiler/truthinessCallExpressionCoercion1.ts(3,5): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? -tests/cases/compiler/truthinessCallExpressionCoercion1.ts(19,5): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? -tests/cases/compiler/truthinessCallExpressionCoercion1.ts(33,5): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? -tests/cases/compiler/truthinessCallExpressionCoercion1.ts(46,5): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? -tests/cases/compiler/truthinessCallExpressionCoercion1.ts(76,9): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion1.ts(3,5): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion1.ts(19,5): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion1.ts(33,5): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion1.ts(46,5): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion1.ts(76,9): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? ==== tests/cases/compiler/truthinessCallExpressionCoercion1.ts (5 errors) ==== @@ -10,7 +10,7 @@ tests/cases/compiler/truthinessCallExpressionCoercion1.ts(76,9): error TS2774: T // error required ? console.log('required') : undefined; ~~~~~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? // ok optional ? console.log('optional') : undefined; @@ -28,7 +28,7 @@ tests/cases/compiler/truthinessCallExpressionCoercion1.ts(76,9): error TS2774: T // error test ? console.log('test') : undefined; ~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? // ok test ? console.log(test) : undefined; @@ -44,7 +44,7 @@ tests/cases/compiler/truthinessCallExpressionCoercion1.ts(76,9): error TS2774: T // error test ~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? ? [() => null].forEach(test => { test() }) : undefined; } @@ -59,7 +59,7 @@ tests/cases/compiler/truthinessCallExpressionCoercion1.ts(76,9): error TS2774: T // error x.foo.bar ? console.log('x.foo.bar') : undefined; ~~~~~~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? // ok x.foo.bar ? x.foo.bar : undefined; @@ -91,7 +91,7 @@ tests/cases/compiler/truthinessCallExpressionCoercion1.ts(76,9): error TS2774: T // error this.isUser ? console.log('this.isUser') : undefined; ~~~~~~~~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? // ok this.maybeIsUser ? console.log('this.maybeIsUser') : undefined; diff --git a/tests/baselines/reference/truthinessCallExpressionCoercion2.errors.txt b/tests/baselines/reference/truthinessCallExpressionCoercion2.errors.txt index 6582157de84c3..d744718a8de45 100644 --- a/tests/baselines/reference/truthinessCallExpressionCoercion2.errors.txt +++ b/tests/baselines/reference/truthinessCallExpressionCoercion2.errors.txt @@ -1,14 +1,14 @@ -tests/cases/compiler/truthinessCallExpressionCoercion2.ts(11,5): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? -tests/cases/compiler/truthinessCallExpressionCoercion2.ts(14,10): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? -tests/cases/compiler/truthinessCallExpressionCoercion2.ts(41,18): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? -tests/cases/compiler/truthinessCallExpressionCoercion2.ts(44,9): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? -tests/cases/compiler/truthinessCallExpressionCoercion2.ts(48,11): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? -tests/cases/compiler/truthinessCallExpressionCoercion2.ts(65,46): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? -tests/cases/compiler/truthinessCallExpressionCoercion2.ts(76,5): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? -tests/cases/compiler/truthinessCallExpressionCoercion2.ts(79,10): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? -tests/cases/compiler/truthinessCallExpressionCoercion2.ts(99,5): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? -tests/cases/compiler/truthinessCallExpressionCoercion2.ts(109,9): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? -tests/cases/compiler/truthinessCallExpressionCoercion2.ts(112,14): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion2.ts(11,5): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion2.ts(14,10): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion2.ts(41,18): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion2.ts(44,9): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion2.ts(48,11): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion2.ts(65,46): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion2.ts(76,5): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion2.ts(79,10): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion2.ts(99,5): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion2.ts(109,9): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? +tests/cases/compiler/truthinessCallExpressionCoercion2.ts(112,14): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? ==== tests/cases/compiler/truthinessCallExpressionCoercion2.ts (11 errors) ==== @@ -24,12 +24,12 @@ tests/cases/compiler/truthinessCallExpressionCoercion2.ts(112,14): error TS2774: // error required1 && console.log('required'); ~~~~~~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? // error 1 && required1 && console.log('required'); ~~~~~~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? // ok required1 && required1(); @@ -58,18 +58,18 @@ tests/cases/compiler/truthinessCallExpressionCoercion2.ts(112,14): error TS2774: // error required1 && required2 && required1() && console.log('foo'); ~~~~~~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? // error if (required1 && b) { ~~~~~~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? } // error if (((required1 && b))) { ~~~~~~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? } // ok @@ -88,7 +88,7 @@ tests/cases/compiler/truthinessCallExpressionCoercion2.ts(112,14): error TS2774: typeof window !== 'undefined' && window.console && ((window.console as any).firebug || (window.console.exception && window.console.table)); ~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? } function checksPropertyAccess() { @@ -101,12 +101,12 @@ tests/cases/compiler/truthinessCallExpressionCoercion2.ts(112,14): error TS2774: // error x.foo.bar && console.log('x.foo.bar'); ~~~~~~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? // error 1 && x.foo.bar && console.log('x.foo.bar'); ~~~~~~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? // ok x.foo.bar && x.foo.bar(); @@ -128,7 +128,7 @@ tests/cases/compiler/truthinessCallExpressionCoercion2.ts(112,14): error TS2774: // error x1.a.b.c && x2.a.b.c(); ~~~~~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? } class Foo { @@ -140,12 +140,12 @@ tests/cases/compiler/truthinessCallExpressionCoercion2.ts(112,14): error TS2774: // error this.required && console.log('required'); ~~~~~~~~~~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? // error 1 && this.required && console.log('required'); ~~~~~~~~~~~~~ -!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead? +!!! error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead? // ok this.required && this.required(); diff --git a/tests/baselines/reference/truthinessPromiseCoercion.errors.txt b/tests/baselines/reference/truthinessPromiseCoercion.errors.txt index a7b7afff1f67b..aaba8031475d6 100644 --- a/tests/baselines/reference/truthinessPromiseCoercion.errors.txt +++ b/tests/baselines/reference/truthinessPromiseCoercion.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/truthinessPromiseCoercion.ts(5,9): error TS2367: This condition will always return 'true' since the types 'Promise' and 'false' have no overlap. -tests/cases/compiler/truthinessPromiseCoercion.ts(9,5): error TS2367: This condition will always return 'true' since the types 'Promise' and 'false' have no overlap. +tests/cases/compiler/truthinessPromiseCoercion.ts(5,9): error TS2801: This condition will always return true since this 'Promise' appears to always be defined. +tests/cases/compiler/truthinessPromiseCoercion.ts(9,5): error TS2801: This condition will always return true since this 'Promise' appears to always be defined. ==== tests/cases/compiler/truthinessPromiseCoercion.ts (2 errors) ==== @@ -9,14 +9,14 @@ tests/cases/compiler/truthinessPromiseCoercion.ts(9,5): error TS2367: This condi async function f() { if (p) {} // err ~ -!!! error TS2367: This condition will always return 'true' since the types 'Promise' and 'false' have no overlap. +!!! error TS2801: This condition will always return true since this 'Promise' appears to always be defined. !!! related TS2773 tests/cases/compiler/truthinessPromiseCoercion.ts:5:9: Did you forget to use 'await'? if (!!p) {} // no err if (p2) {} // no err p ? f.arguments : f.arguments; ~ -!!! error TS2367: This condition will always return 'true' since the types 'Promise' and 'false' have no overlap. +!!! error TS2801: This condition will always return true since this 'Promise' appears to always be defined. !!! related TS2773 tests/cases/compiler/truthinessPromiseCoercion.ts:9:5: Did you forget to use 'await'? !!p ? f.arguments : f.arguments; p2 ? f.arguments : f.arguments;