From 26f7cd30726d740b4b7e0d1c7fba1a837095ac02 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 9 Jul 2024 21:51:09 -0700 Subject: [PATCH 01/12] Check ?? and truthiness checks for suspicious expression syntax --- src/compiler/checker.ts | 76 +++- src/compiler/diagnosticMessages.json | 12 + .../reference/checkJsdocReturnTag1.errors.txt | 28 ++ .../reference/checkJsdocReturnTag2.errors.txt | 5 +- .../computedPropertyNames46_ES5.errors.txt | 9 + .../computedPropertyNames46_ES6.errors.txt | 9 + .../computedPropertyNames48_ES5.errors.txt | 23 + .../computedPropertyNames48_ES5.types | 2 + .../computedPropertyNames48_ES6.errors.txt | 23 + .../computedPropertyNames48_ES6.types | 2 + ...alOperatorConditionIsNumberType.errors.txt | 84 ++++ ...itionalOperatorConditionIsNumberType.types | 23 + ...alOperatorConditionIsObjectType.errors.txt | 38 +- ...ionalOperatorConditoinIsAnyType.errors.txt | 81 ++++ ...onditionalOperatorConditoinIsAnyType.types | 63 +++ ...alOperatorConditoinIsStringType.errors.txt | 103 +++++ ...itionalOperatorConditoinIsStringType.types | 23 + .../baselines/reference/constEnum4.errors.txt | 13 + .../contextuallyTypeLogicalAnd03.errors.txt | 7 +- .../contextuallyTypingOrOperator.errors.txt | 12 + .../contextuallyTypingOrOperator.types | 2 + .../contextuallyTypingOrOperator2.errors.txt | 9 + .../contextuallyTypingOrOperator2.types | 2 + .../controlFlowForStatement.errors.txt | 51 +++ ...declFileTypeAnnotationParenType.errors.txt | 18 + ...clarationEmitInferredTypeAlias1.errors.txt | 15 + ...clarationEmitInferredTypeAlias2.errors.txt | 18 + ...clarationEmitInferredTypeAlias3.errors.txt | 15 + ...clarationEmitInferredTypeAlias5.errors.txt | 14 + ...clarationEmitInferredTypeAlias6.errors.txt | 15 + ...clarationEmitInferredTypeAlias7.errors.txt | 12 + ...structuringParameterProperties1.errors.txt | 5 +- ...onentiationOperatorSyntaxError2.errors.txt | 8 +- ...idSimpleUnaryExpressionOperands.errors.txt | 8 +- .../fatarrowfunctionsOptionalArgs.errors.txt | 5 +- .../reference/for-inStatements.errors.txt | 11 +- .../for-inStatementsInvalid.errors.txt | 11 +- .../generatedContextualTyping.errors.txt | 405 ++++++++++++++++++ .../reference/generatedContextualTyping.types | 3 + .../reference/ifDoWhileStatements.errors.txt | 237 ++++++++++ .../reference/ifDoWhileStatements.types | 8 + .../reference/initializersWidened.errors.txt | 33 ++ .../reference/initializersWidened.types | 6 + ...gicalNotOperatorWithBooleanType.errors.txt | 5 +- ...ogicalNotOperatorWithNumberType.errors.txt | 8 +- ...ogicalNotOperatorWithStringType.errors.txt | 14 +- ...OrExpressionIsContextuallyTyped.errors.txt | 5 +- ...nericParentMethodPropUnions-100.errors.txt | 98 +++++ .../reference/nestedIfStatement.errors.txt | 15 + .../reference/noImplicitAnyForIn.errors.txt | 5 +- .../nullishCoalescingOperator1.errors.txt | 71 +++ .../nullishCoalescingOperator7.errors.txt | 24 ++ .../parserArrowFunctionExpression3.errors.txt | 5 +- .../parserRegularExpression3.errors.txt | 7 +- ...aryOperatorsOnExportedVariables.errors.txt | 35 ++ .../reference/primitiveMembers.errors.txt | 5 +- .../reference/shebangError.errors.txt | 5 +- ...gLiteralsWithSwitchStatements03.errors.txt | 14 +- ...gLiteralsWithSwitchStatements04.errors.txt | 17 +- .../reference/symbolType11.errors.txt | 13 + .../typeGuardsInIfStatement.errors.txt | 5 +- .../reference/voidAsOperator.errors.txt | 15 + tests/baselines/reference/witness.errors.txt | 8 +- 63 files changed, 1894 insertions(+), 27 deletions(-) create mode 100644 tests/baselines/reference/checkJsdocReturnTag1.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames46_ES5.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames46_ES6.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames48_ES5.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNames48_ES6.errors.txt create mode 100644 tests/baselines/reference/conditionalOperatorConditionIsNumberType.errors.txt create mode 100644 tests/baselines/reference/conditionalOperatorConditoinIsAnyType.errors.txt create mode 100644 tests/baselines/reference/conditionalOperatorConditoinIsStringType.errors.txt create mode 100644 tests/baselines/reference/constEnum4.errors.txt create mode 100644 tests/baselines/reference/contextuallyTypingOrOperator.errors.txt create mode 100644 tests/baselines/reference/contextuallyTypingOrOperator2.errors.txt create mode 100644 tests/baselines/reference/controlFlowForStatement.errors.txt create mode 100644 tests/baselines/reference/declFileTypeAnnotationParenType.errors.txt create mode 100644 tests/baselines/reference/declarationEmitInferredTypeAlias1.errors.txt create mode 100644 tests/baselines/reference/declarationEmitInferredTypeAlias2.errors.txt create mode 100644 tests/baselines/reference/declarationEmitInferredTypeAlias3.errors.txt create mode 100644 tests/baselines/reference/declarationEmitInferredTypeAlias5.errors.txt create mode 100644 tests/baselines/reference/declarationEmitInferredTypeAlias6.errors.txt create mode 100644 tests/baselines/reference/declarationEmitInferredTypeAlias7.errors.txt create mode 100644 tests/baselines/reference/generatedContextualTyping.errors.txt create mode 100644 tests/baselines/reference/ifDoWhileStatements.errors.txt create mode 100644 tests/baselines/reference/initializersWidened.errors.txt create mode 100644 tests/baselines/reference/mergeSameGenericParentMethodPropUnions-100.errors.txt create mode 100644 tests/baselines/reference/nestedIfStatement.errors.txt create mode 100644 tests/baselines/reference/nullishCoalescingOperator1.errors.txt create mode 100644 tests/baselines/reference/nullishCoalescingOperator7.errors.txt create mode 100644 tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.errors.txt create mode 100644 tests/baselines/reference/symbolType11.errors.txt create mode 100644 tests/baselines/reference/voidAsOperator.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b31f54a89b7b8..a4735e4658802 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1114,6 +1114,7 @@ import { WideningContext, WithStatement, YieldExpression, + NoSubstitutionTemplateLiteral, } from "./_namespaces/ts.js"; import * as moduleSpecifiers from "./_namespaces/ts.moduleSpecifiers.js"; import * as performance from "./_namespaces/ts.performance.js"; @@ -39450,7 +39451,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return state; } - checkGrammarNullishCoalesceWithLogicalExpression(node); + checkNullishCoalesceOperands(node); const operator = node.operatorToken.kind; if (operator === SyntaxKind.EqualsToken && (node.left.kind === SyntaxKind.ObjectLiteralExpression || node.left.kind === SyntaxKind.ArrayLiteralExpression)) { @@ -39549,7 +39550,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } - function checkGrammarNullishCoalesceWithLogicalExpression(node: BinaryExpression) { + function checkNullishCoalesceOperands(node: BinaryExpression) { const { left, operatorToken, right } = node; if (operatorToken.kind === SyntaxKind.QuestionQuestionToken) { if (isBinaryExpression(left) && (left.operatorToken.kind === SyntaxKind.BarBarToken || left.operatorToken.kind === SyntaxKind.AmpersandAmpersandToken)) { @@ -39558,7 +39559,41 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (isBinaryExpression(right) && (right.operatorToken.kind === SyntaxKind.BarBarToken || right.operatorToken.kind === SyntaxKind.AmpersandAmpersandToken)) { grammarErrorOnNode(right, Diagnostics._0_and_1_operations_cannot_be_mixed_without_parentheses, tokenToString(right.operatorToken.kind), tokenToString(operatorToken.kind)); } + + const leftTarget = skipOuterExpressions(left, OuterExpressionKinds.All); + if (hasStaticNullishness(leftTarget)) { + error(leftTarget, Diagnostics.Using_on_this_expression_appears_unintentional_because_it_always_evaluates_to_the_same_nullishness); + } + } + } + + // Returns true if we know that, syntactically, a node will always (or never) + // evaluate to undefined or null + function hasStaticNullishness(node: Node) { + switch (node.kind) { + case SyntaxKind.AwaitExpression: + case SyntaxKind.CallExpression: + case SyntaxKind.ElementAccessExpression: + case SyntaxKind.Identifier: + case SyntaxKind.NewExpression: + case SyntaxKind.PropertyAccessExpression: + case SyntaxKind.YieldExpression: + return false; + case SyntaxKind.BinaryExpression: + // List of operators that can produce null/undefined: + // = ??= ?? || ||= && &&= + switch ((node as BinaryExpression).operatorToken.kind) { + case SyntaxKind.EqualsToken: + case SyntaxKind.QuestionQuestionToken: + case SyntaxKind.QuestionQuestionEqualsToken: + case SyntaxKind.BarBarToken: + case SyntaxKind.BarBarEqualsToken: + case SyntaxKind.AmpersandAmpersandToken: + case SyntaxKind.AmpersandAmpersandEqualsToken: + return false; + } } + return true; } // Note that this and `checkBinaryExpression` above should behave mostly the same, except this elides some @@ -44190,12 +44225,47 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function checkTruthinessOfType(type: Type, node: Node) { + node = skipParentheses(node); + if (type.flags & TypeFlags.Void) { error(node, Diagnostics.An_expression_of_type_void_cannot_be_tested_for_truthiness); } + + let alwaysTruthy: boolean | undefined = undefined; + switch (node.kind) { + case SyntaxKind.NumericLiteral: + // Allow `while(0)` or `while(1)` + if ((node as NumericLiteral).text === "0" || (node as NumericLiteral).text === "1") break; + // falls through + case SyntaxKind.ArrayLiteralExpression: + case SyntaxKind.ArrowFunction: + case SyntaxKind.BigIntLiteral: + case SyntaxKind.ClassExpression: + case SyntaxKind.FunctionExpression: + case SyntaxKind.JsxElement: + case SyntaxKind.JsxSelfClosingElement: + case SyntaxKind.ObjectLiteralExpression: + case SyntaxKind.RegularExpressionLiteral: + alwaysTruthy = true; + break; + case SyntaxKind.VoidExpression: + alwaysTruthy = false; + break; + case SyntaxKind.NoSubstitutionTemplateLiteral: + case SyntaxKind.StringLiteral: + alwaysTruthy = !!(node as StringLiteral | NoSubstitutionTemplateLiteral).text; + break; + } + + if (alwaysTruthy !== undefined) { + error(node, + alwaysTruthy ? + Diagnostics.This_expression_is_always_truthy_Did_you_mean_to_test_something_else : + Diagnostics.This_expression_is_always_falsy_Did_you_mean_to_test_something_else); + } + return type; } - function checkTruthinessExpression(node: Expression, checkMode?: CheckMode) { return checkTruthinessOfType(checkExpression(node, checkMode), node); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 8c40f2f860ee7..2e06af5f8e9c3 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3911,6 +3911,18 @@ "category": "Error", "code": 2868 }, + "This expression is always truthy. Did you mean to test something else?": { + "category": "Error", + "code": 2869 + }, + "This expression is always falsy. Did you mean to test something else?": { + "category": "Error", + "code": 2870 + }, + "Using ?? on this expression appears unintentional because it always evaluates to the same nullishness.": { + "category": "Error", + "code": 2871 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/tests/baselines/reference/checkJsdocReturnTag1.errors.txt b/tests/baselines/reference/checkJsdocReturnTag1.errors.txt new file mode 100644 index 0000000000000..c2910d41f5030 --- /dev/null +++ b/tests/baselines/reference/checkJsdocReturnTag1.errors.txt @@ -0,0 +1,28 @@ +returns.js(20,12): error TS2869: This expression is always truthy. Did you mean to test something else? + + +==== returns.js (1 errors) ==== + // @ts-check + /** + * @returns {string} This comment is not currently exposed + */ + function f() { + return "hello"; + } + + /** + * @returns {string=} This comment is not currently exposed + */ + function f1() { + return "hello world"; + } + + /** + * @returns {string|number} This comment is not currently exposed + */ + function f2() { + return 5 || "hello"; + ~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + } + \ No newline at end of file diff --git a/tests/baselines/reference/checkJsdocReturnTag2.errors.txt b/tests/baselines/reference/checkJsdocReturnTag2.errors.txt index 1af147cc8fae9..4ac177cc3233c 100644 --- a/tests/baselines/reference/checkJsdocReturnTag2.errors.txt +++ b/tests/baselines/reference/checkJsdocReturnTag2.errors.txt @@ -1,9 +1,10 @@ returns.js(6,5): error TS2322: Type 'number' is not assignable to type 'string'. returns.js(13,5): error TS2322: Type 'number | boolean' is not assignable to type 'string | number'. Type 'boolean' is not assignable to type 'string | number'. +returns.js(13,12): error TS2869: This expression is always truthy. Did you mean to test something else? -==== returns.js (2 errors) ==== +==== returns.js (3 errors) ==== // @ts-check /** * @returns {string} This comment is not currently exposed @@ -22,5 +23,7 @@ returns.js(13,5): error TS2322: Type 'number | boolean' is not assignable to typ ~~~~~~ !!! error TS2322: Type 'number | boolean' is not assignable to type 'string | number'. !!! error TS2322: Type 'boolean' is not assignable to type 'string | number'. + ~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames46_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames46_ES5.errors.txt new file mode 100644 index 0000000000000..aea4963dd8754 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames46_ES5.errors.txt @@ -0,0 +1,9 @@ +computedPropertyNames46_ES5.ts(2,6): error TS2870: This expression is always falsy. Did you mean to test something else? + + +==== computedPropertyNames46_ES5.ts (1 errors) ==== + var o = { + ["" || 0]: 0 + ~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? + }; \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames46_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames46_ES6.errors.txt new file mode 100644 index 0000000000000..b3efc06a9dea2 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames46_ES6.errors.txt @@ -0,0 +1,9 @@ +computedPropertyNames46_ES6.ts(2,6): error TS2870: This expression is always falsy. Did you mean to test something else? + + +==== computedPropertyNames46_ES6.ts (1 errors) ==== + var o = { + ["" || 0]: 0 + ~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? + }; \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames48_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames48_ES5.errors.txt new file mode 100644 index 0000000000000..00d1841816315 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames48_ES5.errors.txt @@ -0,0 +1,23 @@ +computedPropertyNames48_ES5.ts(16,6): error TS2870: This expression is always falsy. Did you mean to test something else? + + +==== computedPropertyNames48_ES5.ts (1 errors) ==== + declare function extractIndexer(p: { [n: number]: T }): T; + + enum E { x } + + var a: any; + + extractIndexer({ + [a]: "" + }); // Should return string + + extractIndexer({ + [E.x]: "" + }); // Should return string + + extractIndexer({ + ["" || 0]: "" + ~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? + }); // Should return any (widened form of undefined) \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames48_ES5.types b/tests/baselines/reference/computedPropertyNames48_ES5.types index c3729ec41f0bf..94a8541879a4d 100644 --- a/tests/baselines/reference/computedPropertyNames48_ES5.types +++ b/tests/baselines/reference/computedPropertyNames48_ES5.types @@ -17,6 +17,7 @@ enum E { x } var a: any; >a : any +> : ^^^ extractIndexer({ >extractIndexer({ [a]: ""}) : string @@ -30,6 +31,7 @@ extractIndexer({ >[a] : string > : ^^^^^^ >a : any +> : ^^^ >"" : "" > : ^^ diff --git a/tests/baselines/reference/computedPropertyNames48_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames48_ES6.errors.txt new file mode 100644 index 0000000000000..f26c5092f6b55 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNames48_ES6.errors.txt @@ -0,0 +1,23 @@ +computedPropertyNames48_ES6.ts(16,6): error TS2870: This expression is always falsy. Did you mean to test something else? + + +==== computedPropertyNames48_ES6.ts (1 errors) ==== + declare function extractIndexer(p: { [n: number]: T }): T; + + enum E { x } + + var a: any; + + extractIndexer({ + [a]: "" + }); // Should return string + + extractIndexer({ + [E.x]: "" + }); // Should return string + + extractIndexer({ + ["" || 0]: "" + ~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? + }); // Should return any (widened form of undefined) \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames48_ES6.types b/tests/baselines/reference/computedPropertyNames48_ES6.types index 4c0d97a7815c0..f472c49e97a25 100644 --- a/tests/baselines/reference/computedPropertyNames48_ES6.types +++ b/tests/baselines/reference/computedPropertyNames48_ES6.types @@ -17,6 +17,7 @@ enum E { x } var a: any; >a : any +> : ^^^ extractIndexer({ >extractIndexer({ [a]: ""}) : string @@ -30,6 +31,7 @@ extractIndexer({ >[a] : string > : ^^^^^^ >a : any +> : ^^^ >"" : "" > : ^^ diff --git a/tests/baselines/reference/conditionalOperatorConditionIsNumberType.errors.txt b/tests/baselines/reference/conditionalOperatorConditionIsNumberType.errors.txt new file mode 100644 index 0000000000000..85db59cd34926 --- /dev/null +++ b/tests/baselines/reference/conditionalOperatorConditionIsNumberType.errors.txt @@ -0,0 +1,84 @@ +conditionalOperatorConditionIsNumberType.ts(27,1): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsNumberType.ts(29,1): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsNumberType.ts(30,1): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsNumberType.ts(53,23): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsNumberType.ts(55,23): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsNumberType.ts(56,32): error TS2869: This expression is always truthy. Did you mean to test something else? + + +==== conditionalOperatorConditionIsNumberType.ts (6 errors) ==== + //Cond ? Expr1 : Expr2, Cond is of number type, Expr1 and Expr2 have the same type + var condNumber: number; + + var exprAny1: any; + var exprBoolean1: boolean; + var exprNumber1: number; + var exprString1: string; + var exprIsObject1: Object; + + var exprAny2: any; + var exprBoolean2: boolean; + var exprNumber2: number; + var exprString2: string; + var exprIsObject2: Object; + + //Cond is a number type variable + condNumber ? exprAny1 : exprAny2; + condNumber ? exprBoolean1 : exprBoolean2; + condNumber ? exprNumber1 : exprNumber2; + condNumber ? exprString1 : exprString2; + condNumber ? exprIsObject1 : exprIsObject2; + condNumber ? exprString1 : exprBoolean1; // Union + + //Cond is a number type literal + 1 ? exprAny1 : exprAny2; + 0 ? exprBoolean1 : exprBoolean2; + 0.123456789 ? exprNumber1 : exprNumber2; + ~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + - 10000000000000 ? exprString1 : exprString2; + 1000000000000 ? exprIsObject1 : exprIsObject2; + ~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + 10000 ? exprString1 : exprBoolean1; // Union + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + + //Cond is a number type expression + function foo() { return 1 }; + var array = [1, 2, 3]; + + 1 * 0 ? exprAny1 : exprAny2; + 1 + 1 ? exprBoolean1 : exprBoolean2; + "string".length ? exprNumber1 : exprNumber2; + foo() ? exprString1 : exprString2; + foo() / array[1] ? exprIsObject1 : exprIsObject2; + foo() ? exprString1 : exprBoolean1; // Union + + //Results shoud be same as Expr1 and Expr2 + var resultIsAny1 = condNumber ? exprAny1 : exprAny2; + var resultIsBoolean1 = condNumber ? exprBoolean1 : exprBoolean2; + var resultIsNumber1 = condNumber ? exprNumber1 : exprNumber2; + var resultIsString1 = condNumber ? exprString1 : exprString2; + var resultIsObject1 = condNumber ? exprIsObject1 : exprIsObject2; + var resultIsStringOrBoolean1 = condNumber ? exprString1 : exprBoolean1; // Union + + var resultIsAny2 = 1 ? exprAny1 : exprAny2; + var resultIsBoolean2 = 0 ? exprBoolean1 : exprBoolean2; + var resultIsNumber2 = 0.123456789 ? exprNumber1 : exprNumber2; + ~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var resultIsString2 = - 10000000000000 ? exprString1 : exprString2; + var resultIsObject2 = 1000000000000 ? exprIsObject1 : exprIsObject2; + ~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var resultIsStringOrBoolean2 = 10000 ? exprString1 : exprBoolean1; // Union + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + + var resultIsAny3 = 1 * 0 ? exprAny1 : exprAny2; + var resultIsBoolean3 = 1 + 1 ? exprBoolean1 : exprBoolean2; + var resultIsNumber3 = "string".length ? exprNumber1 : exprNumber2; + var resultIsString3 = foo() ? exprString1 : exprString2; + var resultIsObject3 = foo() / array[1] ? exprIsObject1 : exprIsObject2; + var resultIsStringOrBoolean3 = foo() / array[1] ? exprString1 : exprBoolean1; // Union \ No newline at end of file diff --git a/tests/baselines/reference/conditionalOperatorConditionIsNumberType.types b/tests/baselines/reference/conditionalOperatorConditionIsNumberType.types index bcb8ead9fdc54..86fcebd2a4e87 100644 --- a/tests/baselines/reference/conditionalOperatorConditionIsNumberType.types +++ b/tests/baselines/reference/conditionalOperatorConditionIsNumberType.types @@ -8,6 +8,7 @@ var condNumber: number; var exprAny1: any; >exprAny1 : any +> : ^^^ var exprBoolean1: boolean; >exprBoolean1 : boolean @@ -27,6 +28,7 @@ var exprIsObject1: Object; var exprAny2: any; >exprAny2 : any +> : ^^^ var exprBoolean2: boolean; >exprBoolean2 : boolean @@ -47,10 +49,13 @@ var exprIsObject2: Object; //Cond is a number type variable condNumber ? exprAny1 : exprAny2; >condNumber ? exprAny1 : exprAny2 : any +> : ^^^ >condNumber : number > : ^^^^^^ >exprAny1 : any +> : ^^^ >exprAny2 : any +> : ^^^ condNumber ? exprBoolean1 : exprBoolean2; >condNumber ? exprBoolean1 : exprBoolean2 : boolean @@ -105,10 +110,13 @@ condNumber ? exprString1 : exprBoolean1; // Union //Cond is a number type literal 1 ? exprAny1 : exprAny2; >1 ? exprAny1 : exprAny2 : any +> : ^^^ >1 : 1 > : ^ >exprAny1 : any +> : ^^^ >exprAny2 : any +> : ^^^ 0 ? exprBoolean1 : exprBoolean2; >0 ? exprBoolean1 : exprBoolean2 : boolean @@ -183,6 +191,7 @@ var array = [1, 2, 3]; 1 * 0 ? exprAny1 : exprAny2; >1 * 0 ? exprAny1 : exprAny2 : any +> : ^^^ >1 * 0 : number > : ^^^^^^ >1 : 1 @@ -190,7 +199,9 @@ var array = [1, 2, 3]; >0 : 0 > : ^ >exprAny1 : any +> : ^^^ >exprAny2 : any +> : ^^^ 1 + 1 ? exprBoolean1 : exprBoolean2; >1 + 1 ? exprBoolean1 : exprBoolean2 : boolean @@ -267,11 +278,15 @@ foo() ? exprString1 : exprBoolean1; // Union //Results shoud be same as Expr1 and Expr2 var resultIsAny1 = condNumber ? exprAny1 : exprAny2; >resultIsAny1 : any +> : ^^^ >condNumber ? exprAny1 : exprAny2 : any +> : ^^^ >condNumber : number > : ^^^^^^ >exprAny1 : any +> : ^^^ >exprAny2 : any +> : ^^^ var resultIsBoolean1 = condNumber ? exprBoolean1 : exprBoolean2; >resultIsBoolean1 : boolean @@ -335,11 +350,15 @@ var resultIsStringOrBoolean1 = condNumber ? exprString1 : exprBoolean1; // Union var resultIsAny2 = 1 ? exprAny1 : exprAny2; >resultIsAny2 : any +> : ^^^ >1 ? exprAny1 : exprAny2 : any +> : ^^^ >1 : 1 > : ^ >exprAny1 : any +> : ^^^ >exprAny2 : any +> : ^^^ var resultIsBoolean2 = 0 ? exprBoolean1 : exprBoolean2; >resultIsBoolean2 : boolean @@ -405,7 +424,9 @@ var resultIsStringOrBoolean2 = 10000 ? exprString1 : exprBoolean1; // Union var resultIsAny3 = 1 * 0 ? exprAny1 : exprAny2; >resultIsAny3 : any +> : ^^^ >1 * 0 ? exprAny1 : exprAny2 : any +> : ^^^ >1 * 0 : number > : ^^^^^^ >1 : 1 @@ -413,7 +434,9 @@ var resultIsAny3 = 1 * 0 ? exprAny1 : exprAny2; >0 : 0 > : ^ >exprAny1 : any +> : ^^^ >exprAny2 : any +> : ^^^ var resultIsBoolean3 = 1 + 1 ? exprBoolean1 : exprBoolean2; >resultIsBoolean3 : boolean diff --git a/tests/baselines/reference/conditionalOperatorConditionIsObjectType.errors.txt b/tests/baselines/reference/conditionalOperatorConditionIsObjectType.errors.txt index d627e668ca6e6..092830b257a63 100644 --- a/tests/baselines/reference/conditionalOperatorConditionIsObjectType.errors.txt +++ b/tests/baselines/reference/conditionalOperatorConditionIsObjectType.errors.txt @@ -1,11 +1,23 @@ +conditionalOperatorConditionIsObjectType.ts(28,2): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(29,2): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(30,2): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(31,2): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(32,2): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(33,2): error TS2869: This expression is always truthy. Did you mean to test something else? conditionalOperatorConditionIsObjectType.ts(36,1): error TS1345: An expression of type 'void' cannot be tested for truthiness. conditionalOperatorConditionIsObjectType.ts(39,1): error TS1345: An expression of type 'void' cannot be tested for truthiness. +conditionalOperatorConditionIsObjectType.ts(51,21): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(52,25): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(53,24): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(54,24): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(55,24): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(56,33): error TS2869: This expression is always truthy. Did you mean to test something else? conditionalOperatorConditionIsObjectType.ts(58,20): error TS1345: An expression of type 'void' cannot be tested for truthiness. conditionalOperatorConditionIsObjectType.ts(61,23): error TS1345: An expression of type 'void' cannot be tested for truthiness. conditionalOperatorConditionIsObjectType.ts(63,32): error TS1345: An expression of type 'void' cannot be tested for truthiness. -==== conditionalOperatorConditionIsObjectType.ts (5 errors) ==== +==== conditionalOperatorConditionIsObjectType.ts (17 errors) ==== //Cond ? Expr1 : Expr2, Cond is of object type, Expr1 and Expr2 have the same type var condObject: Object; @@ -34,11 +46,23 @@ conditionalOperatorConditionIsObjectType.ts(63,32): error TS1345: An expression //Cond is an object type literal ((a: string) => a.length) ? exprAny1 : exprAny2; + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? ((a: string) => a.length) ? exprBoolean1 : exprBoolean2; + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? ({}) ? exprNumber1 : exprNumber2; + ~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? ({ a: 1, b: "s" }) ? exprString1 : exprString2; + ~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? ({ a: 1, b: "s" }) ? exprIsObject1 : exprIsObject2; + ~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? ({ a: 1, b: "s" }) ? exprString1: exprBoolean1; // union + ~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? //Cond is an object type expression foo() ? exprAny1 : exprAny2; @@ -61,11 +85,23 @@ conditionalOperatorConditionIsObjectType.ts(63,32): error TS1345: An expression var resultIsStringOrBoolean1 = condObject ? exprString1 : exprBoolean1; // union var resultIsAny2 = ((a: string) => a.length) ? exprAny1 : exprAny2; + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? var resultIsBoolean2 = ((a: string) => a.length) ? exprBoolean1 : exprBoolean2; + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? var resultIsNumber2 = ({}) ? exprNumber1 : exprNumber2; + ~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? var resultIsString2 = ({ a: 1, b: "s" }) ? exprString1 : exprString2; + ~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? var resultIsObject2 = ({ a: 1, b: "s" }) ? exprIsObject1 : exprIsObject2; + ~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? var resultIsStringOrBoolean2 = ({ a: 1, b: "s" }) ? exprString1 : exprBoolean1; // union + ~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? var resultIsAny3 = foo() ? exprAny1 : exprAny2; ~~~~~ diff --git a/tests/baselines/reference/conditionalOperatorConditoinIsAnyType.errors.txt b/tests/baselines/reference/conditionalOperatorConditoinIsAnyType.errors.txt new file mode 100644 index 0000000000000..34e6bd8a183c3 --- /dev/null +++ b/tests/baselines/reference/conditionalOperatorConditoinIsAnyType.errors.txt @@ -0,0 +1,81 @@ +conditionalOperatorConditoinIsAnyType.ts(29,1): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditoinIsAnyType.ts(30,1): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditoinIsAnyType.ts(52,23): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditoinIsAnyType.ts(53,23): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditoinIsAnyType.ts(56,32): error TS2869: This expression is always truthy. Did you mean to test something else? + + +==== conditionalOperatorConditoinIsAnyType.ts (5 errors) ==== + //Cond ? Expr1 : Expr2, Cond is of any type, Expr1 and Expr2 have the same type + var condAny: any; + var x: any; + + var exprAny1: any; + var exprBoolean1: boolean; + var exprNumber1: number; + var exprString1: string; + var exprIsObject1: Object; + + var exprAny2: any; + var exprBoolean2: boolean; + var exprNumber2: number; + var exprString2: string; + var exprIsObject2: Object; + + //Cond is an any type variable + condAny ? exprAny1 : exprAny2; + condAny ? exprBoolean1 : exprBoolean2; + condAny ? exprNumber1 : exprNumber2; + condAny ? exprString1 : exprString2; + condAny ? exprIsObject1 : exprIsObject2; + condAny ? exprString1 : exprBoolean1; // union + + //Cond is an any type literal + null ? exprAny1 : exprAny2; + null ? exprBoolean1 : exprBoolean2; + undefined ? exprNumber1 : exprNumber2; + [null, undefined] ? exprString1 : exprString2; + ~~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + [null, undefined] ? exprIsObject1 : exprIsObject2; + ~~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + undefined ? exprString1 : exprBoolean1; // union + + //Cond is an any type expression + x.doSomeThing() ? exprAny1 : exprAny2; + x("x") ? exprBoolean1 : exprBoolean2; + x(x) ? exprNumber1 : exprNumber2; + x("x") ? exprString1 : exprString2; + x.doSomeThing() ? exprIsObject1 : exprIsObject2; + x.doSomeThing() ? exprString1 : exprBoolean1; // union + + //Results shoud be same as Expr1 and Expr2 + var resultIsAny1 = condAny ? exprAny1 : exprAny2; + var resultIsBoolean1 = condAny ? exprBoolean1 : exprBoolean2; + var resultIsNumber1 = condAny ? exprNumber1 : exprNumber2; + var resultIsString1 = condAny ? exprString1 : exprString2; + var resultIsObject1 = condAny ? exprIsObject1 : exprIsObject2; + var resultIsStringOrBoolean1 = condAny ? exprString1 : exprBoolean1; // union + + var resultIsAny2 = null ? exprAny1 : exprAny2; + var resultIsBoolean2 = null ? exprBoolean1 : exprBoolean2; + var resultIsNumber2 = undefined ? exprNumber1 : exprNumber2; + var resultIsString2 = [null, undefined] ? exprString1 : exprString2; + ~~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var resultIsObject2 = [null, undefined] ? exprIsObject1 : exprIsObject2; + ~~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var resultIsStringOrBoolean2 = null ? exprString1 : exprBoolean1; // union + var resultIsStringOrBoolean3 = undefined ? exprString1 : exprBoolean1; // union + var resultIsStringOrBoolean4 = [null, undefined] ? exprString1 : exprBoolean1; // union + ~~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + + var resultIsAny3 = x.doSomeThing() ? exprAny1 : exprAny2; + var resultIsBoolean3 = x("x") ? exprBoolean1 : exprBoolean2; + var resultIsNumber3 = x(x) ? exprNumber1 : exprNumber2; + var resultIsString3 = x("x") ? exprString1 : exprString2; + var resultIsObject3 = x.doSomeThing() ? exprIsObject1 : exprIsObject2; + var resultIsStringOrBoolean5 = x.doSomeThing() ? exprString1 : exprBoolean1; // union \ No newline at end of file diff --git a/tests/baselines/reference/conditionalOperatorConditoinIsAnyType.types b/tests/baselines/reference/conditionalOperatorConditoinIsAnyType.types index e2e4c1c5db93d..d26cb2b476158 100644 --- a/tests/baselines/reference/conditionalOperatorConditoinIsAnyType.types +++ b/tests/baselines/reference/conditionalOperatorConditoinIsAnyType.types @@ -4,12 +4,15 @@ //Cond ? Expr1 : Expr2, Cond is of any type, Expr1 and Expr2 have the same type var condAny: any; >condAny : any +> : ^^^ var x: any; >x : any +> : ^^^ var exprAny1: any; >exprAny1 : any +> : ^^^ var exprBoolean1: boolean; >exprBoolean1 : boolean @@ -29,6 +32,7 @@ var exprIsObject1: Object; var exprAny2: any; >exprAny2 : any +> : ^^^ var exprBoolean2: boolean; >exprBoolean2 : boolean @@ -49,14 +53,19 @@ var exprIsObject2: Object; //Cond is an any type variable condAny ? exprAny1 : exprAny2; >condAny ? exprAny1 : exprAny2 : any +> : ^^^ >condAny : any +> : ^^^ >exprAny1 : any +> : ^^^ >exprAny2 : any +> : ^^^ condAny ? exprBoolean1 : exprBoolean2; >condAny ? exprBoolean1 : exprBoolean2 : boolean > : ^^^^^^^ >condAny : any +> : ^^^ >exprBoolean1 : boolean > : ^^^^^^^ >exprBoolean2 : boolean @@ -66,6 +75,7 @@ condAny ? exprNumber1 : exprNumber2; >condAny ? exprNumber1 : exprNumber2 : number > : ^^^^^^ >condAny : any +> : ^^^ >exprNumber1 : number > : ^^^^^^ >exprNumber2 : number @@ -75,6 +85,7 @@ condAny ? exprString1 : exprString2; >condAny ? exprString1 : exprString2 : string > : ^^^^^^ >condAny : any +> : ^^^ >exprString1 : string > : ^^^^^^ >exprString2 : string @@ -84,6 +95,7 @@ condAny ? exprIsObject1 : exprIsObject2; >condAny ? exprIsObject1 : exprIsObject2 : Object > : ^^^^^^ >condAny : any +> : ^^^ >exprIsObject1 : Object > : ^^^^^^ >exprIsObject2 : Object @@ -93,6 +105,7 @@ condAny ? exprString1 : exprBoolean1; // union >condAny ? exprString1 : exprBoolean1 : string | boolean > : ^^^^^^^^^^^^^^^^ >condAny : any +> : ^^^ >exprString1 : string > : ^^^^^^ >exprBoolean1 : boolean @@ -101,8 +114,11 @@ condAny ? exprString1 : exprBoolean1; // union //Cond is an any type literal null ? exprAny1 : exprAny2; >null ? exprAny1 : exprAny2 : any +> : ^^^ >exprAny1 : any +> : ^^^ >exprAny2 : any +> : ^^^ null ? exprBoolean1 : exprBoolean2; >null ? exprBoolean1 : exprBoolean2 : boolean @@ -159,20 +175,27 @@ undefined ? exprString1 : exprBoolean1; // union //Cond is an any type expression x.doSomeThing() ? exprAny1 : exprAny2; >x.doSomeThing() ? exprAny1 : exprAny2 : any +> : ^^^ >x.doSomeThing() : any +> : ^^^ >x.doSomeThing : any +> : ^^^ >x : any > : ^^^ >doSomeThing : any > : ^^^ >exprAny1 : any +> : ^^^ >exprAny2 : any +> : ^^^ x("x") ? exprBoolean1 : exprBoolean2; >x("x") ? exprBoolean1 : exprBoolean2 : boolean > : ^^^^^^^ >x("x") : any +> : ^^^ >x : any +> : ^^^ >"x" : "x" > : ^^^ >exprBoolean1 : boolean @@ -184,8 +207,11 @@ x(x) ? exprNumber1 : exprNumber2; >x(x) ? exprNumber1 : exprNumber2 : number > : ^^^^^^ >x(x) : any +> : ^^^ >x : any +> : ^^^ >x : any +> : ^^^ >exprNumber1 : number > : ^^^^^^ >exprNumber2 : number @@ -195,7 +221,9 @@ x("x") ? exprString1 : exprString2; >x("x") ? exprString1 : exprString2 : string > : ^^^^^^ >x("x") : any +> : ^^^ >x : any +> : ^^^ >"x" : "x" > : ^^^ >exprString1 : string @@ -207,7 +235,9 @@ x.doSomeThing() ? exprIsObject1 : exprIsObject2; >x.doSomeThing() ? exprIsObject1 : exprIsObject2 : Object > : ^^^^^^ >x.doSomeThing() : any +> : ^^^ >x.doSomeThing : any +> : ^^^ >x : any > : ^^^ >doSomeThing : any @@ -221,7 +251,9 @@ x.doSomeThing() ? exprString1 : exprBoolean1; // union >x.doSomeThing() ? exprString1 : exprBoolean1 : string | boolean > : ^^^^^^^^^^^^^^^^ >x.doSomeThing() : any +> : ^^^ >x.doSomeThing : any +> : ^^^ >x : any > : ^^^ >doSomeThing : any @@ -234,10 +266,15 @@ x.doSomeThing() ? exprString1 : exprBoolean1; // union //Results shoud be same as Expr1 and Expr2 var resultIsAny1 = condAny ? exprAny1 : exprAny2; >resultIsAny1 : any +> : ^^^ >condAny ? exprAny1 : exprAny2 : any +> : ^^^ >condAny : any +> : ^^^ >exprAny1 : any +> : ^^^ >exprAny2 : any +> : ^^^ var resultIsBoolean1 = condAny ? exprBoolean1 : exprBoolean2; >resultIsBoolean1 : boolean @@ -245,6 +282,7 @@ var resultIsBoolean1 = condAny ? exprBoolean1 : exprBoolean2; >condAny ? exprBoolean1 : exprBoolean2 : boolean > : ^^^^^^^ >condAny : any +> : ^^^ >exprBoolean1 : boolean > : ^^^^^^^ >exprBoolean2 : boolean @@ -256,6 +294,7 @@ var resultIsNumber1 = condAny ? exprNumber1 : exprNumber2; >condAny ? exprNumber1 : exprNumber2 : number > : ^^^^^^ >condAny : any +> : ^^^ >exprNumber1 : number > : ^^^^^^ >exprNumber2 : number @@ -267,6 +306,7 @@ var resultIsString1 = condAny ? exprString1 : exprString2; >condAny ? exprString1 : exprString2 : string > : ^^^^^^ >condAny : any +> : ^^^ >exprString1 : string > : ^^^^^^ >exprString2 : string @@ -278,6 +318,7 @@ var resultIsObject1 = condAny ? exprIsObject1 : exprIsObject2; >condAny ? exprIsObject1 : exprIsObject2 : Object > : ^^^^^^ >condAny : any +> : ^^^ >exprIsObject1 : Object > : ^^^^^^ >exprIsObject2 : Object @@ -289,6 +330,7 @@ var resultIsStringOrBoolean1 = condAny ? exprString1 : exprBoolean1; // union >condAny ? exprString1 : exprBoolean1 : string | boolean > : ^^^^^^^^^^^^^^^^ >condAny : any +> : ^^^ >exprString1 : string > : ^^^^^^ >exprBoolean1 : boolean @@ -296,9 +338,13 @@ var resultIsStringOrBoolean1 = condAny ? exprString1 : exprBoolean1; // union var resultIsAny2 = null ? exprAny1 : exprAny2; >resultIsAny2 : any +> : ^^^ >null ? exprAny1 : exprAny2 : any +> : ^^^ >exprAny1 : any +> : ^^^ >exprAny2 : any +> : ^^^ var resultIsBoolean2 = null ? exprBoolean1 : exprBoolean2; >resultIsBoolean2 : boolean @@ -388,15 +434,21 @@ var resultIsStringOrBoolean4 = [null, undefined] ? exprString1 : exprBoolean1; / var resultIsAny3 = x.doSomeThing() ? exprAny1 : exprAny2; >resultIsAny3 : any +> : ^^^ >x.doSomeThing() ? exprAny1 : exprAny2 : any +> : ^^^ >x.doSomeThing() : any +> : ^^^ >x.doSomeThing : any +> : ^^^ >x : any > : ^^^ >doSomeThing : any > : ^^^ >exprAny1 : any +> : ^^^ >exprAny2 : any +> : ^^^ var resultIsBoolean3 = x("x") ? exprBoolean1 : exprBoolean2; >resultIsBoolean3 : boolean @@ -404,7 +456,9 @@ var resultIsBoolean3 = x("x") ? exprBoolean1 : exprBoolean2; >x("x") ? exprBoolean1 : exprBoolean2 : boolean > : ^^^^^^^ >x("x") : any +> : ^^^ >x : any +> : ^^^ >"x" : "x" > : ^^^ >exprBoolean1 : boolean @@ -418,8 +472,11 @@ var resultIsNumber3 = x(x) ? exprNumber1 : exprNumber2; >x(x) ? exprNumber1 : exprNumber2 : number > : ^^^^^^ >x(x) : any +> : ^^^ >x : any +> : ^^^ >x : any +> : ^^^ >exprNumber1 : number > : ^^^^^^ >exprNumber2 : number @@ -431,7 +488,9 @@ var resultIsString3 = x("x") ? exprString1 : exprString2; >x("x") ? exprString1 : exprString2 : string > : ^^^^^^ >x("x") : any +> : ^^^ >x : any +> : ^^^ >"x" : "x" > : ^^^ >exprString1 : string @@ -445,7 +504,9 @@ var resultIsObject3 = x.doSomeThing() ? exprIsObject1 : exprIsObject2; >x.doSomeThing() ? exprIsObject1 : exprIsObject2 : Object > : ^^^^^^ >x.doSomeThing() : any +> : ^^^ >x.doSomeThing : any +> : ^^^ >x : any > : ^^^ >doSomeThing : any @@ -461,7 +522,9 @@ var resultIsStringOrBoolean5 = x.doSomeThing() ? exprString1 : exprBoolean1; // >x.doSomeThing() ? exprString1 : exprBoolean1 : string | boolean > : ^^^^^^^^^^^^^^^^ >x.doSomeThing() : any +> : ^^^ >x.doSomeThing : any +> : ^^^ >x : any > : ^^^ >doSomeThing : any diff --git a/tests/baselines/reference/conditionalOperatorConditoinIsStringType.errors.txt b/tests/baselines/reference/conditionalOperatorConditoinIsStringType.errors.txt new file mode 100644 index 0000000000000..ea5d8e13427a8 --- /dev/null +++ b/tests/baselines/reference/conditionalOperatorConditoinIsStringType.errors.txt @@ -0,0 +1,103 @@ +conditionalOperatorConditoinIsStringType.ts(25,1): error TS2870: This expression is always falsy. Did you mean to test something else? +conditionalOperatorConditoinIsStringType.ts(26,1): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditoinIsStringType.ts(27,1): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditoinIsStringType.ts(28,1): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditoinIsStringType.ts(29,1): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditoinIsStringType.ts(30,1): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditoinIsStringType.ts(51,20): error TS2870: This expression is always falsy. Did you mean to test something else? +conditionalOperatorConditoinIsStringType.ts(52,24): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditoinIsStringType.ts(53,23): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditoinIsStringType.ts(54,23): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditoinIsStringType.ts(55,23): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditoinIsStringType.ts(56,32): error TS2869: This expression is always truthy. Did you mean to test something else? + + +==== conditionalOperatorConditoinIsStringType.ts (12 errors) ==== + //Cond ? Expr1 : Expr2, Cond is of string type, Expr1 and Expr2 have the same type + var condString: string; + + var exprAny1: any; + var exprBoolean1: boolean; + var exprNumber1: number; + var exprString1: string; + var exprIsObject1: Object; + + var exprAny2: any; + var exprBoolean2: boolean; + var exprNumber2: number; + var exprString2: string; + var exprIsObject2: Object; + + //Cond is a string type variable + condString ? exprAny1 : exprAny2; + condString ? exprBoolean1 : exprBoolean2; + condString ? exprNumber1 : exprNumber2; + condString ? exprString1 : exprString2; + condString ? exprIsObject1 : exprIsObject2; + condString ? exprString1 : exprBoolean1; // union + + //Cond is a string type literal + "" ? exprAny1 : exprAny2; + ~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? + "string" ? exprBoolean1 : exprBoolean2; + ~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + 'c' ? exprNumber1 : exprNumber2; + ~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + 'string' ? exprString1 : exprString2; + ~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + " " ? exprIsObject1 : exprIsObject2; + ~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + "hello " ? exprString1 : exprBoolean1; // union + ~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + + //Cond is a string type expression + function foo() { return "string" }; + var array = ["1", "2", "3"]; + + typeof condString ? exprAny1 : exprAny2; + condString.toUpperCase ? exprBoolean1 : exprBoolean2; + condString + "string" ? exprNumber1 : exprNumber2; + foo() ? exprString1 : exprString2; + array[1] ? exprIsObject1 : exprIsObject2; + foo() ? exprString1 : exprBoolean1; // union + + //Results shoud be same as Expr1 and Expr2 + var resultIsAny1 = condString ? exprAny1 : exprAny2; + var resultIsBoolean1 = condString ? exprBoolean1 : exprBoolean2; + var resultIsNumber1 = condString ? exprNumber1 : exprNumber2; + var resultIsString1 = condString ? exprString1 : exprString2; + var resultIsObject1 = condString ? exprIsObject1 : exprIsObject2; + var resultIsStringOrBoolean1 = condString ? exprString1 : exprBoolean1; // union + + var resultIsAny2 = "" ? exprAny1 : exprAny2; + ~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? + var resultIsBoolean2 = "string" ? exprBoolean1 : exprBoolean2; + ~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var resultIsNumber2 = 'c' ? exprNumber1 : exprNumber2; + ~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var resultIsString2 = 'string' ? exprString1 : exprString2; + ~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var resultIsObject2 = " " ? exprIsObject1 : exprIsObject2; + ~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var resultIsStringOrBoolean2 = "hello" ? exprString1 : exprBoolean1; // union + ~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + + var resultIsAny3 = typeof condString ? exprAny1 : exprAny2; + var resultIsBoolean3 = condString.toUpperCase ? exprBoolean1 : exprBoolean2; + var resultIsNumber3 = condString + "string" ? exprNumber1 : exprNumber2; + var resultIsString3 = foo() ? exprString1 : exprString2; + var resultIsObject3 = array[1] ? exprIsObject1 : exprIsObject2; + var resultIsStringOrBoolean3 = typeof condString ? exprString1 : exprBoolean1; // union + var resultIsStringOrBoolean4 = condString.toUpperCase ? exprString1 : exprBoolean1; // union \ No newline at end of file diff --git a/tests/baselines/reference/conditionalOperatorConditoinIsStringType.types b/tests/baselines/reference/conditionalOperatorConditoinIsStringType.types index 25f1e9c51dd01..b3f211f4e959e 100644 --- a/tests/baselines/reference/conditionalOperatorConditoinIsStringType.types +++ b/tests/baselines/reference/conditionalOperatorConditoinIsStringType.types @@ -8,6 +8,7 @@ var condString: string; var exprAny1: any; >exprAny1 : any +> : ^^^ var exprBoolean1: boolean; >exprBoolean1 : boolean @@ -27,6 +28,7 @@ var exprIsObject1: Object; var exprAny2: any; >exprAny2 : any +> : ^^^ var exprBoolean2: boolean; >exprBoolean2 : boolean @@ -47,10 +49,13 @@ var exprIsObject2: Object; //Cond is a string type variable condString ? exprAny1 : exprAny2; >condString ? exprAny1 : exprAny2 : any +> : ^^^ >condString : string > : ^^^^^^ >exprAny1 : any +> : ^^^ >exprAny2 : any +> : ^^^ condString ? exprBoolean1 : exprBoolean2; >condString ? exprBoolean1 : exprBoolean2 : boolean @@ -105,10 +110,13 @@ condString ? exprString1 : exprBoolean1; // union //Cond is a string type literal "" ? exprAny1 : exprAny2; >"" ? exprAny1 : exprAny2 : any +> : ^^^ >"" : "" > : ^^ >exprAny1 : any +> : ^^^ >exprAny2 : any +> : ^^^ "string" ? exprBoolean1 : exprBoolean2; >"string" ? exprBoolean1 : exprBoolean2 : boolean @@ -181,12 +189,15 @@ var array = ["1", "2", "3"]; typeof condString ? exprAny1 : exprAny2; >typeof condString ? exprAny1 : exprAny2 : any +> : ^^^ >typeof condString : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >condString : string > : ^^^^^^ >exprAny1 : any +> : ^^^ >exprAny2 : any +> : ^^^ condString.toUpperCase ? exprBoolean1 : exprBoolean2; >condString.toUpperCase ? exprBoolean1 : exprBoolean2 : boolean @@ -257,11 +268,15 @@ foo() ? exprString1 : exprBoolean1; // union //Results shoud be same as Expr1 and Expr2 var resultIsAny1 = condString ? exprAny1 : exprAny2; >resultIsAny1 : any +> : ^^^ >condString ? exprAny1 : exprAny2 : any +> : ^^^ >condString : string > : ^^^^^^ >exprAny1 : any +> : ^^^ >exprAny2 : any +> : ^^^ var resultIsBoolean1 = condString ? exprBoolean1 : exprBoolean2; >resultIsBoolean1 : boolean @@ -325,11 +340,15 @@ var resultIsStringOrBoolean1 = condString ? exprString1 : exprBoolean1; // union var resultIsAny2 = "" ? exprAny1 : exprAny2; >resultIsAny2 : any +> : ^^^ >"" ? exprAny1 : exprAny2 : any +> : ^^^ >"" : "" > : ^^ >exprAny1 : any +> : ^^^ >exprAny2 : any +> : ^^^ var resultIsBoolean2 = "string" ? exprBoolean1 : exprBoolean2; >resultIsBoolean2 : boolean @@ -393,13 +412,17 @@ var resultIsStringOrBoolean2 = "hello" ? exprString1 : exprBoolean1; // union var resultIsAny3 = typeof condString ? exprAny1 : exprAny2; >resultIsAny3 : any +> : ^^^ >typeof condString ? exprAny1 : exprAny2 : any +> : ^^^ >typeof condString : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >condString : string > : ^^^^^^ >exprAny1 : any +> : ^^^ >exprAny2 : any +> : ^^^ var resultIsBoolean3 = condString.toUpperCase ? exprBoolean1 : exprBoolean2; >resultIsBoolean3 : boolean diff --git a/tests/baselines/reference/constEnum4.errors.txt b/tests/baselines/reference/constEnum4.errors.txt new file mode 100644 index 0000000000000..8cb45b4573c52 --- /dev/null +++ b/tests/baselines/reference/constEnum4.errors.txt @@ -0,0 +1,13 @@ +constEnum4.ts(3,10): error TS2869: This expression is always truthy. Did you mean to test something else? + + +==== constEnum4.ts (1 errors) ==== + if (1) + const enum A { } + else if (2) + ~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + const enum B { } + else + const enum C { } + \ No newline at end of file diff --git a/tests/baselines/reference/contextuallyTypeLogicalAnd03.errors.txt b/tests/baselines/reference/contextuallyTypeLogicalAnd03.errors.txt index 1a9af2f022141..df7bbfcf26124 100644 --- a/tests/baselines/reference/contextuallyTypeLogicalAnd03.errors.txt +++ b/tests/baselines/reference/contextuallyTypeLogicalAnd03.errors.txt @@ -1,10 +1,13 @@ contextuallyTypeLogicalAnd03.ts(4,6): error TS7006: Parameter 'a' implicitly has an 'any' type. +contextuallyTypeLogicalAnd03.ts(4,6): error TS2869: This expression is always truthy. Did you mean to test something else? -==== contextuallyTypeLogicalAnd03.ts (1 errors) ==== +==== contextuallyTypeLogicalAnd03.ts (2 errors) ==== let x: (a: string) => string; let y = true; x = (a => a) && (b => b); ~ -!!! error TS7006: Parameter 'a' implicitly has an 'any' type. \ No newline at end of file +!!! error TS7006: Parameter 'a' implicitly has an 'any' type. + ~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? \ No newline at end of file diff --git a/tests/baselines/reference/contextuallyTypingOrOperator.errors.txt b/tests/baselines/reference/contextuallyTypingOrOperator.errors.txt new file mode 100644 index 0000000000000..ccb12aa6dc6f9 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypingOrOperator.errors.txt @@ -0,0 +1,12 @@ +contextuallyTypingOrOperator.ts(1,39): error TS2869: This expression is always truthy. Did you mean to test something else? + + +==== contextuallyTypingOrOperator.ts (1 errors) ==== + var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 }; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + + var v2 = (s: string) => s.length || function (s) { s.length }; + + var v3 = (s: string) => s.length || function (s: number) { return 1 }; + var v4 = (s: number) => 1 || function (s: string) { return s.length }; \ No newline at end of file diff --git a/tests/baselines/reference/contextuallyTypingOrOperator.types b/tests/baselines/reference/contextuallyTypingOrOperator.types index db43f05ee5bfa..1c143986b1b7e 100644 --- a/tests/baselines/reference/contextuallyTypingOrOperator.types +++ b/tests/baselines/reference/contextuallyTypingOrOperator.types @@ -53,7 +53,9 @@ var v2 = (s: string) => s.length || function (s) { s.length }; >function (s) { s.length } : (s: any) => void > : ^ ^^^^^^^^^^^^^^ >s : any +> : ^^^ >s.length : any +> : ^^^ >s : any > : ^^^ >length : any diff --git a/tests/baselines/reference/contextuallyTypingOrOperator2.errors.txt b/tests/baselines/reference/contextuallyTypingOrOperator2.errors.txt new file mode 100644 index 0000000000000..00955c9ead550 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypingOrOperator2.errors.txt @@ -0,0 +1,9 @@ +contextuallyTypingOrOperator2.ts(1,39): error TS2869: This expression is always truthy. Did you mean to test something else? + + +==== contextuallyTypingOrOperator2.ts (1 errors) ==== + var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 }; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + + var v2 = (s: string) => s.length || function (s) { s.aaa }; \ No newline at end of file diff --git a/tests/baselines/reference/contextuallyTypingOrOperator2.types b/tests/baselines/reference/contextuallyTypingOrOperator2.types index ba5cbcd97555a..f0613664e64c0 100644 --- a/tests/baselines/reference/contextuallyTypingOrOperator2.types +++ b/tests/baselines/reference/contextuallyTypingOrOperator2.types @@ -53,7 +53,9 @@ var v2 = (s: string) => s.length || function (s) { s.aaa }; >function (s) { s.aaa } : (s: any) => void > : ^ ^^^^^^^^^^^^^^ >s : any +> : ^^^ >s.aaa : any +> : ^^^ >s : any > : ^^^ >aaa : any diff --git a/tests/baselines/reference/controlFlowForStatement.errors.txt b/tests/baselines/reference/controlFlowForStatement.errors.txt new file mode 100644 index 0000000000000..db1f9e0616d1d --- /dev/null +++ b/tests/baselines/reference/controlFlowForStatement.errors.txt @@ -0,0 +1,51 @@ +controlFlowForStatement.ts(29,14): error TS2870: This expression is always falsy. Did you mean to test something else? +controlFlowForStatement.ts(29,50): error TS2870: This expression is always falsy. Did you mean to test something else? + + +==== controlFlowForStatement.ts (2 errors) ==== + let cond: boolean; + function a() { + let x: string | number | boolean; + for (x = ""; cond; x = 5) { + x; // string | number + } + } + function b() { + let x: string | number | boolean; + for (x = 5; cond; x = x.length) { + x; // number + x = ""; + } + } + function c() { + let x: string | number | boolean; + for (x = 5; x = x.toExponential(); x = 5) { + x; // string + } + } + function d() { + let x: string | number | boolean; + for (x = ""; typeof x === "string"; x = 5) { + x; // string + } + } + function e() { + let x: string | number | boolean | RegExp; + for (x = "" || 0; typeof x !== "string"; x = "" || true) { + ~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? + ~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? + x; // number | boolean + } + } + function f() { + let x: string | number | boolean; + for (; typeof x !== "string";) { + x; // number | boolean + if (typeof x === "number") break; + x = undefined; + } + x; // string | number + } + \ No newline at end of file diff --git a/tests/baselines/reference/declFileTypeAnnotationParenType.errors.txt b/tests/baselines/reference/declFileTypeAnnotationParenType.errors.txt new file mode 100644 index 0000000000000..81772f25bb03a --- /dev/null +++ b/tests/baselines/reference/declFileTypeAnnotationParenType.errors.txt @@ -0,0 +1,18 @@ +declFileTypeAnnotationParenType.ts(8,30): error TS2869: This expression is always truthy. Did you mean to test something else? +declFileTypeAnnotationParenType.ts(9,10): error TS2869: This expression is always truthy. Did you mean to test something else? + + +==== declFileTypeAnnotationParenType.ts (2 errors) ==== + class c { + private p: string; + } + + var x: (() => c)[] = [() => new c()]; + var y = [() => new c()]; + + var k: (() => c) | string = (() => new c()) || ""; + ~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var l = (() => new c()) || ""; + ~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitInferredTypeAlias1.errors.txt b/tests/baselines/reference/declarationEmitInferredTypeAlias1.errors.txt new file mode 100644 index 0000000000000..063ec3cf0bcc8 --- /dev/null +++ b/tests/baselines/reference/declarationEmitInferredTypeAlias1.errors.txt @@ -0,0 +1,15 @@ +1.ts(1,9): error TS2869: This expression is always truthy. Did you mean to test something else? + + +==== 0.ts (0 errors) ==== + { + type Data = string | boolean; + let obj: Data = true; + } + export { } + +==== 1.ts (1 errors) ==== + let v = "str" || true; + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + export { v } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitInferredTypeAlias2.errors.txt b/tests/baselines/reference/declarationEmitInferredTypeAlias2.errors.txt new file mode 100644 index 0000000000000..c63af018e1205 --- /dev/null +++ b/tests/baselines/reference/declarationEmitInferredTypeAlias2.errors.txt @@ -0,0 +1,18 @@ +1.ts(1,9): error TS2869: This expression is always truthy. Did you mean to test something else? + + +==== 0.ts (0 errors) ==== + { + type Data = string | boolean; + let obj: Data = true; + } + export { } + +==== 1.ts (1 errors) ==== + let v = "str" || true; + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + function bar () { + return v; + } + export { v, bar } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitInferredTypeAlias3.errors.txt b/tests/baselines/reference/declarationEmitInferredTypeAlias3.errors.txt new file mode 100644 index 0000000000000..ec2a2a63fe98f --- /dev/null +++ b/tests/baselines/reference/declarationEmitInferredTypeAlias3.errors.txt @@ -0,0 +1,15 @@ +1.ts(1,9): error TS2869: This expression is always truthy. Did you mean to test something else? + + +==== 0.ts (0 errors) ==== + { + type Data = string | boolean; + let obj: Data = true; + } + export { } + +==== 1.ts (1 errors) ==== + var x = "hi" || 5; + ~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + export default x; \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitInferredTypeAlias5.errors.txt b/tests/baselines/reference/declarationEmitInferredTypeAlias5.errors.txt new file mode 100644 index 0000000000000..7ddcc8ef2b952 --- /dev/null +++ b/tests/baselines/reference/declarationEmitInferredTypeAlias5.errors.txt @@ -0,0 +1,14 @@ +1.ts(3,9): error TS2869: This expression is always truthy. Did you mean to test something else? + + +==== 0.ts (0 errors) ==== + export type Data = string | boolean; + let obj: Data = true; + +==== 1.ts (1 errors) ==== + import * as Z from "./0" + //let v2: Z.Data; + let v = "str" || true; + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + export { v } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitInferredTypeAlias6.errors.txt b/tests/baselines/reference/declarationEmitInferredTypeAlias6.errors.txt new file mode 100644 index 0000000000000..063ec3cf0bcc8 --- /dev/null +++ b/tests/baselines/reference/declarationEmitInferredTypeAlias6.errors.txt @@ -0,0 +1,15 @@ +1.ts(1,9): error TS2869: This expression is always truthy. Did you mean to test something else? + + +==== 0.ts (0 errors) ==== + { + type Data = string | boolean; + let obj: Data = true; + } + export { } + +==== 1.ts (1 errors) ==== + let v = "str" || true; + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + export { v } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitInferredTypeAlias7.errors.txt b/tests/baselines/reference/declarationEmitInferredTypeAlias7.errors.txt new file mode 100644 index 0000000000000..618246f0e3b82 --- /dev/null +++ b/tests/baselines/reference/declarationEmitInferredTypeAlias7.errors.txt @@ -0,0 +1,12 @@ +1.ts(1,9): error TS2869: This expression is always truthy. Did you mean to test something else? + + +==== 0.ts (0 errors) ==== + export type Data = string | boolean; + let obj: Data = true; + +==== 1.ts (1 errors) ==== + let v = "str" || true; + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + export { v } \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterProperties1.errors.txt b/tests/baselines/reference/destructuringParameterProperties1.errors.txt index 8759452ef7909..a400cf02515d8 100644 --- a/tests/baselines/reference/destructuringParameterProperties1.errors.txt +++ b/tests/baselines/reference/destructuringParameterProperties1.errors.txt @@ -5,6 +5,7 @@ destructuringParameterProperties1.ts(22,26): error TS2339: Property 'x' does not destructuringParameterProperties1.ts(22,35): error TS2339: Property 'y' does not exist on type 'C1'. destructuringParameterProperties1.ts(22,43): error TS2339: Property 'y' does not exist on type 'C1'. destructuringParameterProperties1.ts(22,52): error TS2339: Property 'z' does not exist on type 'C1'. +destructuringParameterProperties1.ts(24,30): error TS2869: This expression is always truthy. Did you mean to test something else? destructuringParameterProperties1.ts(25,30): error TS2339: Property 'x' does not exist on type 'C2'. destructuringParameterProperties1.ts(25,36): error TS2339: Property 'y' does not exist on type 'C2'. destructuringParameterProperties1.ts(25,42): error TS2339: Property 'z' does not exist on type 'C2'. @@ -13,7 +14,7 @@ destructuringParameterProperties1.ts(29,36): error TS2339: Property 'y' does not destructuringParameterProperties1.ts(29,42): error TS2339: Property 'z' does not exist on type 'C3'. -==== destructuringParameterProperties1.ts (13 errors) ==== +==== destructuringParameterProperties1.ts (14 errors) ==== class C1 { constructor(public [x, y, z]: string[]) { ~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -52,6 +53,8 @@ destructuringParameterProperties1.ts(29,42): error TS2339: Property 'z' does not !!! error TS2339: Property 'z' does not exist on type 'C1'. var c2 = new C2(["10", 10, !!10]); + ~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? var [c2_x, c2_y, c2_z] = [c2.x, c2.y, c2.z]; ~ !!! error TS2339: Property 'x' does not exist on type 'C2'. diff --git a/tests/baselines/reference/exponentiationOperatorSyntaxError2.errors.txt b/tests/baselines/reference/exponentiationOperatorSyntaxError2.errors.txt index bb16988a82e98..91ada32050f74 100644 --- a/tests/baselines/reference/exponentiationOperatorSyntaxError2.errors.txt +++ b/tests/baselines/reference/exponentiationOperatorSyntaxError2.errors.txt @@ -78,6 +78,7 @@ exponentiationOperatorSyntaxError2.ts(52,1): error TS2362: The left-hand side of exponentiationOperatorSyntaxError2.ts(52,1): error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. exponentiationOperatorSyntaxError2.ts(53,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorSyntaxError2.ts(53,1): error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +exponentiationOperatorSyntaxError2.ts(53,2): error TS2869: This expression is always truthy. Did you mean to test something else? exponentiationOperatorSyntaxError2.ts(54,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorSyntaxError2.ts(54,1): error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. exponentiationOperatorSyntaxError2.ts(55,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. @@ -88,6 +89,7 @@ exponentiationOperatorSyntaxError2.ts(58,6): error TS2362: The left-hand side of exponentiationOperatorSyntaxError2.ts(58,6): error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. exponentiationOperatorSyntaxError2.ts(59,6): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorSyntaxError2.ts(59,6): error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +exponentiationOperatorSyntaxError2.ts(59,7): error TS2869: This expression is always truthy. Did you mean to test something else? exponentiationOperatorSyntaxError2.ts(60,6): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorSyntaxError2.ts(60,6): error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. exponentiationOperatorSyntaxError2.ts(61,6): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. @@ -99,7 +101,7 @@ exponentiationOperatorSyntaxError2.ts(66,1): error TS17007: A type assertion exp exponentiationOperatorSyntaxError2.ts(67,1): error TS17007: A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -==== exponentiationOperatorSyntaxError2.ts (99 errors) ==== +==== exponentiationOperatorSyntaxError2.ts (101 errors) ==== // Error: early syntax error using ES7 SimpleUnaryExpression on left-hand side without () var temp: any; @@ -313,6 +315,8 @@ exponentiationOperatorSyntaxError2.ts(67,1): error TS17007: A type assertion exp !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. ~~ !!! error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + ~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? !temp++ ** 4; ~~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. @@ -339,6 +343,8 @@ exponentiationOperatorSyntaxError2.ts(67,1): error TS17007: A type assertion exp !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. ~~ !!! error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + ~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? 1 ** !temp++ ** 4; ~~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. diff --git a/tests/baselines/reference/exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.errors.txt b/tests/baselines/reference/exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.errors.txt index 7c808f5e13e91..7e79af572ccfc 100644 --- a/tests/baselines/reference/exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.errors.txt +++ b/tests/baselines/reference/exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.errors.txt @@ -1,11 +1,13 @@ exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(4,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(5,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(6,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(6,3): error TS2869: This expression is always truthy. Did you mean to test something else? exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(7,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(8,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(10,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(11,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(12,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(12,3): error TS2869: This expression is always truthy. Did you mean to test something else? exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(13,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(14,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(16,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. @@ -36,7 +38,7 @@ exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(36,6): error T exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(36,14): error TS2703: The operand of a 'delete' operator must be a property reference. -==== exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts (36 errors) ==== +==== exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts (38 errors) ==== var temp: any; // Error: incorrect type on left-hand side @@ -49,6 +51,8 @@ exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(36,14): error (!3) ** 4; ~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. + ~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? (!temp++) ** 4; ~~~~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. @@ -65,6 +69,8 @@ exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(36,14): error (!3) ** 4 ** 1; ~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. + ~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? (!temp++) ** 4 ** 1; ~~~~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. diff --git a/tests/baselines/reference/fatarrowfunctionsOptionalArgs.errors.txt b/tests/baselines/reference/fatarrowfunctionsOptionalArgs.errors.txt index 77a6681ce4c2f..41be1498fa39e 100644 --- a/tests/baselines/reference/fatarrowfunctionsOptionalArgs.errors.txt +++ b/tests/baselines/reference/fatarrowfunctionsOptionalArgs.errors.txt @@ -1,8 +1,9 @@ +fatarrowfunctionsOptionalArgs.ts(85,2): error TS2869: This expression is always truthy. Did you mean to test something else? fatarrowfunctionsOptionalArgs.ts(88,23): error TS1005: ';' expected. fatarrowfunctionsOptionalArgs.ts(88,38): error TS1005: ';' expected. -==== fatarrowfunctionsOptionalArgs.ts (2 errors) ==== +==== fatarrowfunctionsOptionalArgs.ts (3 errors) ==== // valid // no params @@ -88,6 +89,8 @@ fatarrowfunctionsOptionalArgs.ts(88,38): error TS1005: ';' expected. // nested ternary expressions ((a?) => { return a; }) ? (b? ) => { return b; } : (c? ) => { return c; }; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? //multiple levels (a?) => { return a; } ? (b)=>(c)=>81 : (c)=>(d)=>82; diff --git a/tests/baselines/reference/for-inStatements.errors.txt b/tests/baselines/reference/for-inStatements.errors.txt index 14170a06bfb83..c5a632ea04a3b 100644 --- a/tests/baselines/reference/for-inStatements.errors.txt +++ b/tests/baselines/reference/for-inStatements.errors.txt @@ -1,9 +1,12 @@ +for-inStatements.ts(21,15): error TS2869: This expression is always truthy. Did you mean to test something else? +for-inStatements.ts(22,15): error TS2870: This expression is always falsy. Did you mean to test something else? +for-inStatements.ts(23,15): error TS2869: This expression is always truthy. Did you mean to test something else? for-inStatements.ts(33,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'Extract'. for-inStatements.ts(50,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'Extract'. for-inStatements.ts(79,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'Color.Blue'. -==== for-inStatements.ts (3 errors) ==== +==== for-inStatements.ts (6 errors) ==== var aString: string; for (aString in {}) { } @@ -25,8 +28,14 @@ for-inStatements.ts(79,15): error TS2407: The right-hand side of a 'for...in' st for (var x in c || d) { } for (var x in e ? c : d) { } for (var x in 42 ? c : d) { } + ~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? for (var x in '' ? c : d) { } + ~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? for (var x in 42 ? d[x] : c[x]) { } + ~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? for (var x in c[d]) { } for (var x in ((x: T) => x)) { } diff --git a/tests/baselines/reference/for-inStatementsInvalid.errors.txt b/tests/baselines/reference/for-inStatementsInvalid.errors.txt index 0b68ca0966ade..30d16b2b32a39 100644 --- a/tests/baselines/reference/for-inStatementsInvalid.errors.txt +++ b/tests/baselines/reference/for-inStatementsInvalid.errors.txt @@ -5,8 +5,11 @@ for-inStatementsInvalid.ts(10,10): error TS2404: The left-hand side of a 'for... for-inStatementsInvalid.ts(13,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'void'. for-inStatementsInvalid.ts(17,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'string'. for-inStatementsInvalid.ts(18,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'string'. +for-inStatementsInvalid.ts(19,15): error TS2869: This expression is always truthy. Did you mean to test something else? for-inStatementsInvalid.ts(19,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'string'. +for-inStatementsInvalid.ts(20,15): error TS2870: This expression is always falsy. Did you mean to test something else? for-inStatementsInvalid.ts(20,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'string'. +for-inStatementsInvalid.ts(21,15): error TS2869: This expression is always truthy. Did you mean to test something else? for-inStatementsInvalid.ts(22,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'string'. for-inStatementsInvalid.ts(29,23): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'number'. for-inStatementsInvalid.ts(31,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'Extract'. @@ -17,7 +20,7 @@ for-inStatementsInvalid.ts(51,23): error TS2407: The right-hand side of a 'for.. for-inStatementsInvalid.ts(62,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'number'. -==== for-inStatementsInvalid.ts (17 errors) ==== +==== for-inStatementsInvalid.ts (20 errors) ==== var aNumber: number; for (aNumber in {}) { } ~~~~~~~ @@ -51,12 +54,18 @@ for-inStatementsInvalid.ts(62,15): error TS2407: The right-hand side of a 'for.. ~~~~~~~~~ !!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'string'. for (var x in 42 ? c : d) { } + ~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? ~~~~~~~~~~ !!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'string'. for (var x in '' ? c : d) { } + ~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? ~~~~~~~~~~ !!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'string'. for (var x in 42 ? d[x] : c[x]) { } + ~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? for (var x in c[23]) { } ~~~~~ !!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'string'. diff --git a/tests/baselines/reference/generatedContextualTyping.errors.txt b/tests/baselines/reference/generatedContextualTyping.errors.txt new file mode 100644 index 0000000000000..d5188e1c3ee4d --- /dev/null +++ b/tests/baselines/reference/generatedContextualTyping.errors.txt @@ -0,0 +1,405 @@ +generatedContextualTyping.ts(259,26): error TS2869: This expression is always truthy. Did you mean to test something else? +generatedContextualTyping.ts(260,35): error TS2869: This expression is always truthy. Did you mean to test something else? +generatedContextualTyping.ts(261,29): error TS2869: This expression is always truthy. Did you mean to test something else? +generatedContextualTyping.ts(262,38): error TS2869: This expression is always truthy. Did you mean to test something else? +generatedContextualTyping.ts(263,20): error TS2869: This expression is always truthy. Did you mean to test something else? +generatedContextualTyping.ts(264,25): error TS2869: This expression is always truthy. Did you mean to test something else? +generatedContextualTyping.ts(265,36): error TS2869: This expression is always truthy. Did you mean to test something else? +generatedContextualTyping.ts(266,28): error TS2869: This expression is always truthy. Did you mean to test something else? +generatedContextualTyping.ts(275,26): error TS2869: This expression is always truthy. Did you mean to test something else? +generatedContextualTyping.ts(276,35): error TS2869: This expression is always truthy. Did you mean to test something else? +generatedContextualTyping.ts(277,29): error TS2869: This expression is always truthy. Did you mean to test something else? +generatedContextualTyping.ts(278,38): error TS2869: This expression is always truthy. Did you mean to test something else? +generatedContextualTyping.ts(279,20): error TS2869: This expression is always truthy. Did you mean to test something else? +generatedContextualTyping.ts(280,25): error TS2869: This expression is always truthy. Did you mean to test something else? +generatedContextualTyping.ts(281,36): error TS2869: This expression is always truthy. Did you mean to test something else? +generatedContextualTyping.ts(282,28): error TS2869: This expression is always truthy. Did you mean to test something else? + + +==== generatedContextualTyping.ts (16 errors) ==== + class Base { private p; } + class Derived1 extends Base { private m; } + class Derived2 extends Base { private n; } + interface Genric { func(n: T[]); } + var b = new Base(), d1 = new Derived1(), d2 = new Derived2(); + var x1: () => Base[] = () => [d1, d2]; + var x2: () => Base[] = function() { return [d1, d2] }; + var x3: () => Base[] = function named() { return [d1, d2] }; + var x4: { (): Base[]; } = () => [d1, d2]; + var x5: { (): Base[]; } = function() { return [d1, d2] }; + var x6: { (): Base[]; } = function named() { return [d1, d2] }; + var x7: Base[] = [d1, d2]; + var x8: Array = [d1, d2]; + var x9: { [n: number]: Base; } = [d1, d2]; + var x10: {n: Base[]; } = { n: [d1, d2] }; + var x11: (s: Base[]) => any = n => { var n: Base[]; return null; }; + var x12: Genric = { func: n => { return [d1, d2]; } }; + class x13 { member: () => Base[] = () => [d1, d2] } + class x14 { member: () => Base[] = function() { return [d1, d2] } } + class x15 { member: () => Base[] = function named() { return [d1, d2] } } + class x16 { member: { (): Base[]; } = () => [d1, d2] } + class x17 { member: { (): Base[]; } = function() { return [d1, d2] } } + class x18 { member: { (): Base[]; } = function named() { return [d1, d2] } } + class x19 { member: Base[] = [d1, d2] } + class x20 { member: Array = [d1, d2] } + class x21 { member: { [n: number]: Base; } = [d1, d2] } + class x22 { member: {n: Base[]; } = { n: [d1, d2] } } + class x23 { member: (s: Base[]) => any = n => { var n: Base[]; return null; } } + class x24 { member: Genric = { func: n => { return [d1, d2]; } } } + class x25 { private member: () => Base[] = () => [d1, d2] } + class x26 { private member: () => Base[] = function() { return [d1, d2] } } + class x27 { private member: () => Base[] = function named() { return [d1, d2] } } + class x28 { private member: { (): Base[]; } = () => [d1, d2] } + class x29 { private member: { (): Base[]; } = function() { return [d1, d2] } } + class x30 { private member: { (): Base[]; } = function named() { return [d1, d2] } } + class x31 { private member: Base[] = [d1, d2] } + class x32 { private member: Array = [d1, d2] } + class x33 { private member: { [n: number]: Base; } = [d1, d2] } + class x34 { private member: {n: Base[]; } = { n: [d1, d2] } } + class x35 { private member: (s: Base[]) => any = n => { var n: Base[]; return null; } } + class x36 { private member: Genric = { func: n => { return [d1, d2]; } } } + class x37 { public member: () => Base[] = () => [d1, d2] } + class x38 { public member: () => Base[] = function() { return [d1, d2] } } + class x39 { public member: () => Base[] = function named() { return [d1, d2] } } + class x40 { public member: { (): Base[]; } = () => [d1, d2] } + class x41 { public member: { (): Base[]; } = function() { return [d1, d2] } } + class x42 { public member: { (): Base[]; } = function named() { return [d1, d2] } } + class x43 { public member: Base[] = [d1, d2] } + class x44 { public member: Array = [d1, d2] } + class x45 { public member: { [n: number]: Base; } = [d1, d2] } + class x46 { public member: {n: Base[]; } = { n: [d1, d2] } } + class x47 { public member: (s: Base[]) => any = n => { var n: Base[]; return null; } } + class x48 { public member: Genric = { func: n => { return [d1, d2]; } } } + class x49 { static member: () => Base[] = () => [d1, d2] } + class x50 { static member: () => Base[] = function() { return [d1, d2] } } + class x51 { static member: () => Base[] = function named() { return [d1, d2] } } + class x52 { static member: { (): Base[]; } = () => [d1, d2] } + class x53 { static member: { (): Base[]; } = function() { return [d1, d2] } } + class x54 { static member: { (): Base[]; } = function named() { return [d1, d2] } } + class x55 { static member: Base[] = [d1, d2] } + class x56 { static member: Array = [d1, d2] } + class x57 { static member: { [n: number]: Base; } = [d1, d2] } + class x58 { static member: {n: Base[]; } = { n: [d1, d2] } } + class x59 { static member: (s: Base[]) => any = n => { var n: Base[]; return null; } } + class x60 { static member: Genric = { func: n => { return [d1, d2]; } } } + class x61 { private static member: () => Base[] = () => [d1, d2] } + class x62 { private static member: () => Base[] = function() { return [d1, d2] } } + class x63 { private static member: () => Base[] = function named() { return [d1, d2] } } + class x64 { private static member: { (): Base[]; } = () => [d1, d2] } + class x65 { private static member: { (): Base[]; } = function() { return [d1, d2] } } + class x66 { private static member: { (): Base[]; } = function named() { return [d1, d2] } } + class x67 { private static member: Base[] = [d1, d2] } + class x68 { private static member: Array = [d1, d2] } + class x69 { private static member: { [n: number]: Base; } = [d1, d2] } + class x70 { private static member: {n: Base[]; } = { n: [d1, d2] } } + class x71 { private static member: (s: Base[]) => any = n => { var n: Base[]; return null; } } + class x72 { private static member: Genric = { func: n => { return [d1, d2]; } } } + class x73 { public static member: () => Base[] = () => [d1, d2] } + class x74 { public static member: () => Base[] = function() { return [d1, d2] } } + class x75 { public static member: () => Base[] = function named() { return [d1, d2] } } + class x76 { public static member: { (): Base[]; } = () => [d1, d2] } + class x77 { public static member: { (): Base[]; } = function() { return [d1, d2] } } + class x78 { public static member: { (): Base[]; } = function named() { return [d1, d2] } } + class x79 { public static member: Base[] = [d1, d2] } + class x80 { public static member: Array = [d1, d2] } + class x81 { public static member: { [n: number]: Base; } = [d1, d2] } + class x82 { public static member: {n: Base[]; } = { n: [d1, d2] } } + class x83 { public static member: (s: Base[]) => any = n => { var n: Base[]; return null; } } + class x84 { public static member: Genric = { func: n => { return [d1, d2]; } } } + class x85 { constructor(parm: () => Base[] = () => [d1, d2]) { } } + class x86 { constructor(parm: () => Base[] = function() { return [d1, d2] }) { } } + class x87 { constructor(parm: () => Base[] = function named() { return [d1, d2] }) { } } + class x88 { constructor(parm: { (): Base[]; } = () => [d1, d2]) { } } + class x89 { constructor(parm: { (): Base[]; } = function() { return [d1, d2] }) { } } + class x90 { constructor(parm: { (): Base[]; } = function named() { return [d1, d2] }) { } } + class x91 { constructor(parm: Base[] = [d1, d2]) { } } + class x92 { constructor(parm: Array = [d1, d2]) { } } + class x93 { constructor(parm: { [n: number]: Base; } = [d1, d2]) { } } + class x94 { constructor(parm: {n: Base[]; } = { n: [d1, d2] }) { } } + class x95 { constructor(parm: (s: Base[]) => any = n => { var n: Base[]; return null; }) { } } + class x96 { constructor(parm: Genric = { func: n => { return [d1, d2]; } }) { } } + class x97 { constructor(public parm: () => Base[] = () => [d1, d2]) { } } + class x98 { constructor(public parm: () => Base[] = function() { return [d1, d2] }) { } } + class x99 { constructor(public parm: () => Base[] = function named() { return [d1, d2] }) { } } + class x100 { constructor(public parm: { (): Base[]; } = () => [d1, d2]) { } } + class x101 { constructor(public parm: { (): Base[]; } = function() { return [d1, d2] }) { } } + class x102 { constructor(public parm: { (): Base[]; } = function named() { return [d1, d2] }) { } } + class x103 { constructor(public parm: Base[] = [d1, d2]) { } } + class x104 { constructor(public parm: Array = [d1, d2]) { } } + class x105 { constructor(public parm: { [n: number]: Base; } = [d1, d2]) { } } + class x106 { constructor(public parm: {n: Base[]; } = { n: [d1, d2] }) { } } + class x107 { constructor(public parm: (s: Base[]) => any = n => { var n: Base[]; return null; }) { } } + class x108 { constructor(public parm: Genric = { func: n => { return [d1, d2]; } }) { } } + class x109 { constructor(private parm: () => Base[] = () => [d1, d2]) { } } + class x110 { constructor(private parm: () => Base[] = function() { return [d1, d2] }) { } } + class x111 { constructor(private parm: () => Base[] = function named() { return [d1, d2] }) { } } + class x112 { constructor(private parm: { (): Base[]; } = () => [d1, d2]) { } } + class x113 { constructor(private parm: { (): Base[]; } = function() { return [d1, d2] }) { } } + class x114 { constructor(private parm: { (): Base[]; } = function named() { return [d1, d2] }) { } } + class x115 { constructor(private parm: Base[] = [d1, d2]) { } } + class x116 { constructor(private parm: Array = [d1, d2]) { } } + class x117 { constructor(private parm: { [n: number]: Base; } = [d1, d2]) { } } + class x118 { constructor(private parm: {n: Base[]; } = { n: [d1, d2] }) { } } + class x119 { constructor(private parm: (s: Base[]) => any = n => { var n: Base[]; return null; }) { } } + class x120 { constructor(private parm: Genric = { func: n => { return [d1, d2]; } }) { } } + function x121(parm: () => Base[] = () => [d1, d2]) { } + function x122(parm: () => Base[] = function() { return [d1, d2] }) { } + function x123(parm: () => Base[] = function named() { return [d1, d2] }) { } + function x124(parm: { (): Base[]; } = () => [d1, d2]) { } + function x125(parm: { (): Base[]; } = function() { return [d1, d2] }) { } + function x126(parm: { (): Base[]; } = function named() { return [d1, d2] }) { } + function x127(parm: Base[] = [d1, d2]) { } + function x128(parm: Array = [d1, d2]) { } + function x129(parm: { [n: number]: Base; } = [d1, d2]) { } + function x130(parm: {n: Base[]; } = { n: [d1, d2] }) { } + function x131(parm: (s: Base[]) => any = n => { var n: Base[]; return null; }) { } + function x132(parm: Genric = { func: n => { return [d1, d2]; } }) { } + function x133(): () => Base[] { return () => [d1, d2]; } + function x134(): () => Base[] { return function() { return [d1, d2] }; } + function x135(): () => Base[] { return function named() { return [d1, d2] }; } + function x136(): { (): Base[]; } { return () => [d1, d2]; } + function x137(): { (): Base[]; } { return function() { return [d1, d2] }; } + function x138(): { (): Base[]; } { return function named() { return [d1, d2] }; } + function x139(): Base[] { return [d1, d2]; } + function x140(): Array { return [d1, d2]; } + function x141(): { [n: number]: Base; } { return [d1, d2]; } + function x142(): {n: Base[]; } { return { n: [d1, d2] }; } + function x143(): (s: Base[]) => any { return n => { var n: Base[]; return null; }; } + function x144(): Genric { return { func: n => { return [d1, d2]; } }; } + function x145(): () => Base[] { return () => [d1, d2]; return () => [d1, d2]; } + function x146(): () => Base[] { return function() { return [d1, d2] }; return function() { return [d1, d2] }; } + function x147(): () => Base[] { return function named() { return [d1, d2] }; return function named() { return [d1, d2] }; } + function x148(): { (): Base[]; } { return () => [d1, d2]; return () => [d1, d2]; } + function x149(): { (): Base[]; } { return function() { return [d1, d2] }; return function() { return [d1, d2] }; } + function x150(): { (): Base[]; } { return function named() { return [d1, d2] }; return function named() { return [d1, d2] }; } + function x151(): Base[] { return [d1, d2]; return [d1, d2]; } + function x152(): Array { return [d1, d2]; return [d1, d2]; } + function x153(): { [n: number]: Base; } { return [d1, d2]; return [d1, d2]; } + function x154(): {n: Base[]; } { return { n: [d1, d2] }; return { n: [d1, d2] }; } + function x155(): (s: Base[]) => any { return n => { var n: Base[]; return null; }; return n => { var n: Base[]; return null; }; } + function x156(): Genric { return { func: n => { return [d1, d2]; } }; return { func: n => { return [d1, d2]; } }; } + var x157: () => () => Base[] = () => { return () => [d1, d2]; }; + var x158: () => () => Base[] = () => { return function() { return [d1, d2] }; }; + var x159: () => () => Base[] = () => { return function named() { return [d1, d2] }; }; + var x160: () => { (): Base[]; } = () => { return () => [d1, d2]; }; + var x161: () => { (): Base[]; } = () => { return function() { return [d1, d2] }; }; + var x162: () => { (): Base[]; } = () => { return function named() { return [d1, d2] }; }; + var x163: () => Base[] = () => { return [d1, d2]; }; + var x164: () => Array = () => { return [d1, d2]; }; + var x165: () => { [n: number]: Base; } = () => { return [d1, d2]; }; + var x166: () => {n: Base[]; } = () => { return { n: [d1, d2] }; }; + var x167: () => (s: Base[]) => any = () => { return n => { var n: Base[]; return null; }; }; + var x168: () => Genric = () => { return { func: n => { return [d1, d2]; } }; }; + var x169: () => () => Base[] = function() { return () => [d1, d2]; }; + var x170: () => () => Base[] = function() { return function() { return [d1, d2] }; }; + var x171: () => () => Base[] = function() { return function named() { return [d1, d2] }; }; + var x172: () => { (): Base[]; } = function() { return () => [d1, d2]; }; + var x173: () => { (): Base[]; } = function() { return function() { return [d1, d2] }; }; + var x174: () => { (): Base[]; } = function() { return function named() { return [d1, d2] }; }; + var x175: () => Base[] = function() { return [d1, d2]; }; + var x176: () => Array = function() { return [d1, d2]; }; + var x177: () => { [n: number]: Base; } = function() { return [d1, d2]; }; + var x178: () => {n: Base[]; } = function() { return { n: [d1, d2] }; }; + var x179: () => (s: Base[]) => any = function() { return n => { var n: Base[]; return null; }; }; + var x180: () => Genric = function() { return { func: n => { return [d1, d2]; } }; }; + module x181 { var t: () => Base[] = () => [d1, d2]; } + module x182 { var t: () => Base[] = function() { return [d1, d2] }; } + module x183 { var t: () => Base[] = function named() { return [d1, d2] }; } + module x184 { var t: { (): Base[]; } = () => [d1, d2]; } + module x185 { var t: { (): Base[]; } = function() { return [d1, d2] }; } + module x186 { var t: { (): Base[]; } = function named() { return [d1, d2] }; } + module x187 { var t: Base[] = [d1, d2]; } + module x188 { var t: Array = [d1, d2]; } + module x189 { var t: { [n: number]: Base; } = [d1, d2]; } + module x190 { var t: {n: Base[]; } = { n: [d1, d2] }; } + module x191 { var t: (s: Base[]) => any = n => { var n: Base[]; return null; }; } + module x192 { var t: Genric = { func: n => { return [d1, d2]; } }; } + module x193 { export var t: () => Base[] = () => [d1, d2]; } + module x194 { export var t: () => Base[] = function() { return [d1, d2] }; } + module x195 { export var t: () => Base[] = function named() { return [d1, d2] }; } + module x196 { export var t: { (): Base[]; } = () => [d1, d2]; } + module x197 { export var t: { (): Base[]; } = function() { return [d1, d2] }; } + module x198 { export var t: { (): Base[]; } = function named() { return [d1, d2] }; } + module x199 { export var t: Base[] = [d1, d2]; } + module x200 { export var t: Array = [d1, d2]; } + module x201 { export var t: { [n: number]: Base; } = [d1, d2]; } + module x202 { export var t: {n: Base[]; } = { n: [d1, d2] }; } + module x203 { export var t: (s: Base[]) => any = n => { var n: Base[]; return null; }; } + module x204 { export var t: Genric = { func: n => { return [d1, d2]; } }; } + var x206 = <() => Base[]>function() { return [d1, d2] }; + var x207 = <() => Base[]>function named() { return [d1, d2] }; + var x209 = <{ (): Base[]; }>function() { return [d1, d2] }; + var x210 = <{ (): Base[]; }>function named() { return [d1, d2] }; + var x211 = [d1, d2]; + var x212 = >[d1, d2]; + var x213 = <{ [n: number]: Base; }>[d1, d2]; + var x214 = <{n: Base[]; } >{ n: [d1, d2] }; + var x216 = >{ func: n => { return [d1, d2]; } }; + var x217 = (<() => Base[]>undefined) || function() { return [d1, d2] }; + var x218 = (<() => Base[]>undefined) || function named() { return [d1, d2] }; + var x219 = (<{ (): Base[]; }>undefined) || function() { return [d1, d2] }; + var x220 = (<{ (): Base[]; }>undefined) || function named() { return [d1, d2] }; + var x221 = (undefined) || [d1, d2]; + var x222 = (>undefined) || [d1, d2]; + var x223 = (<{ [n: number]: Base; }>undefined) || [d1, d2]; + var x224 = (<{n: Base[]; } >undefined) || { n: [d1, d2] }; + var x225: () => Base[]; x225 = () => [d1, d2]; + var x226: () => Base[]; x226 = function() { return [d1, d2] }; + var x227: () => Base[]; x227 = function named() { return [d1, d2] }; + var x228: { (): Base[]; }; x228 = () => [d1, d2]; + var x229: { (): Base[]; }; x229 = function() { return [d1, d2] }; + var x230: { (): Base[]; }; x230 = function named() { return [d1, d2] }; + var x231: Base[]; x231 = [d1, d2]; + var x232: Array; x232 = [d1, d2]; + var x233: { [n: number]: Base; }; x233 = [d1, d2]; + var x234: {n: Base[]; } ; x234 = { n: [d1, d2] }; + var x235: (s: Base[]) => any; x235 = n => { var n: Base[]; return null; }; + var x236: Genric; x236 = { func: n => { return [d1, d2]; } }; + var x237: { n: () => Base[]; } = { n: () => [d1, d2] }; + var x238: { n: () => Base[]; } = { n: function() { return [d1, d2] } }; + var x239: { n: () => Base[]; } = { n: function named() { return [d1, d2] } }; + var x240: { n: { (): Base[]; }; } = { n: () => [d1, d2] }; + var x241: { n: { (): Base[]; }; } = { n: function() { return [d1, d2] } }; + var x242: { n: { (): Base[]; }; } = { n: function named() { return [d1, d2] } }; + var x243: { n: Base[]; } = { n: [d1, d2] }; + var x244: { n: Array; } = { n: [d1, d2] }; + var x245: { n: { [n: number]: Base; }; } = { n: [d1, d2] }; + var x246: { n: {n: Base[]; } ; } = { n: { n: [d1, d2] } }; + var x247: { n: (s: Base[]) => any; } = { n: n => { var n: Base[]; return null; } }; + var x248: { n: Genric; } = { n: { func: n => { return [d1, d2]; } } }; + var x252: { (): Base[]; }[] = [() => [d1, d2]]; + var x253: { (): Base[]; }[] = [function() { return [d1, d2] }]; + var x254: { (): Base[]; }[] = [function named() { return [d1, d2] }]; + var x255: Base[][] = [[d1, d2]]; + var x256: Array[] = [[d1, d2]]; + var x257: { [n: number]: Base; }[] = [[d1, d2]]; + var x258: {n: Base[]; } [] = [{ n: [d1, d2] }]; + var x260: Genric[] = [{ func: n => { return [d1, d2]; } }]; + var x261: () => Base[] = function() { return [d1, d2] } || undefined; + ~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var x262: () => Base[] = function named() { return [d1, d2] } || undefined; + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var x263: { (): Base[]; } = function() { return [d1, d2] } || undefined; + ~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var x264: { (): Base[]; } = function named() { return [d1, d2] } || undefined; + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var x265: Base[] = [d1, d2] || undefined; + ~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var x266: Array = [d1, d2] || undefined; + ~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var x267: { [n: number]: Base; } = [d1, d2] || undefined; + ~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var x268: {n: Base[]; } = { n: [d1, d2] } || undefined; + ~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var x269: () => Base[] = undefined || function() { return [d1, d2] }; + var x270: () => Base[] = undefined || function named() { return [d1, d2] }; + var x271: { (): Base[]; } = undefined || function() { return [d1, d2] }; + var x272: { (): Base[]; } = undefined || function named() { return [d1, d2] }; + var x273: Base[] = undefined || [d1, d2]; + var x274: Array = undefined || [d1, d2]; + var x275: { [n: number]: Base; } = undefined || [d1, d2]; + var x276: {n: Base[]; } = undefined || { n: [d1, d2] }; + var x277: () => Base[] = function() { return [d1, d2] } || function() { return [d1, d2] }; + ~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var x278: () => Base[] = function named() { return [d1, d2] } || function named() { return [d1, d2] }; + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var x279: { (): Base[]; } = function() { return [d1, d2] } || function() { return [d1, d2] }; + ~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var x280: { (): Base[]; } = function named() { return [d1, d2] } || function named() { return [d1, d2] }; + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var x281: Base[] = [d1, d2] || [d1, d2]; + ~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var x282: Array = [d1, d2] || [d1, d2]; + ~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var x283: { [n: number]: Base; } = [d1, d2] || [d1, d2]; + ~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var x284: {n: Base[]; } = { n: [d1, d2] } || { n: [d1, d2] }; + ~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + var x285: () => Base[] = true ? () => [d1, d2] : () => [d1, d2]; + var x286: () => Base[] = true ? function() { return [d1, d2] } : function() { return [d1, d2] }; + var x287: () => Base[] = true ? function named() { return [d1, d2] } : function named() { return [d1, d2] }; + var x288: { (): Base[]; } = true ? () => [d1, d2] : () => [d1, d2]; + var x289: { (): Base[]; } = true ? function() { return [d1, d2] } : function() { return [d1, d2] }; + var x290: { (): Base[]; } = true ? function named() { return [d1, d2] } : function named() { return [d1, d2] }; + var x291: Base[] = true ? [d1, d2] : [d1, d2]; + var x292: Array = true ? [d1, d2] : [d1, d2]; + var x293: { [n: number]: Base; } = true ? [d1, d2] : [d1, d2]; + var x294: {n: Base[]; } = true ? { n: [d1, d2] } : { n: [d1, d2] }; + var x295: (s: Base[]) => any = true ? n => { var n: Base[]; return null; } : n => { var n: Base[]; return null; }; + var x296: Genric = true ? { func: n => { return [d1, d2]; } } : { func: n => { return [d1, d2]; } }; + var x297: () => Base[] = true ? undefined : () => [d1, d2]; + var x298: () => Base[] = true ? undefined : function() { return [d1, d2] }; + var x299: () => Base[] = true ? undefined : function named() { return [d1, d2] }; + var x300: { (): Base[]; } = true ? undefined : () => [d1, d2]; + var x301: { (): Base[]; } = true ? undefined : function() { return [d1, d2] }; + var x302: { (): Base[]; } = true ? undefined : function named() { return [d1, d2] }; + var x303: Base[] = true ? undefined : [d1, d2]; + var x304: Array = true ? undefined : [d1, d2]; + var x305: { [n: number]: Base; } = true ? undefined : [d1, d2]; + var x306: {n: Base[]; } = true ? undefined : { n: [d1, d2] }; + var x307: (s: Base[]) => any = true ? undefined : n => { var n: Base[]; return null; }; + var x308: Genric = true ? undefined : { func: n => { return [d1, d2]; } }; + var x309: () => Base[] = true ? () => [d1, d2] : undefined; + var x310: () => Base[] = true ? function() { return [d1, d2] } : undefined; + var x311: () => Base[] = true ? function named() { return [d1, d2] } : undefined; + var x312: { (): Base[]; } = true ? () => [d1, d2] : undefined; + var x313: { (): Base[]; } = true ? function() { return [d1, d2] } : undefined; + var x314: { (): Base[]; } = true ? function named() { return [d1, d2] } : undefined; + var x315: Base[] = true ? [d1, d2] : undefined; + var x316: Array = true ? [d1, d2] : undefined; + var x317: { [n: number]: Base; } = true ? [d1, d2] : undefined; + var x318: {n: Base[]; } = true ? { n: [d1, d2] } : undefined; + var x319: (s: Base[]) => any = true ? n => { var n: Base[]; return null; } : undefined; + var x320: Genric = true ? { func: n => { return [d1, d2]; } } : undefined; + function x321(n: () => Base[]) { }; x321(() => [d1, d2]); + function x322(n: () => Base[]) { }; x322(function() { return [d1, d2] }); + function x323(n: () => Base[]) { }; x323(function named() { return [d1, d2] }); + function x324(n: { (): Base[]; }) { }; x324(() => [d1, d2]); + function x325(n: { (): Base[]; }) { }; x325(function() { return [d1, d2] }); + function x326(n: { (): Base[]; }) { }; x326(function named() { return [d1, d2] }); + function x327(n: Base[]) { }; x327([d1, d2]); + function x328(n: Array) { }; x328([d1, d2]); + function x329(n: { [n: number]: Base; }) { }; x329([d1, d2]); + function x330(n: {n: Base[]; } ) { }; x330({ n: [d1, d2] }); + function x331(n: (s: Base[]) => any) { }; x331(n => { var n: Base[]; return null; }); + function x332(n: Genric) { }; x332({ func: n => { return [d1, d2]; } }); + var x333 = (n: () => Base[]) => n; x333(() => [d1, d2]); + var x334 = (n: () => Base[]) => n; x334(function() { return [d1, d2] }); + var x335 = (n: () => Base[]) => n; x335(function named() { return [d1, d2] }); + var x336 = (n: { (): Base[]; }) => n; x336(() => [d1, d2]); + var x337 = (n: { (): Base[]; }) => n; x337(function() { return [d1, d2] }); + var x338 = (n: { (): Base[]; }) => n; x338(function named() { return [d1, d2] }); + var x339 = (n: Base[]) => n; x339([d1, d2]); + var x340 = (n: Array) => n; x340([d1, d2]); + var x341 = (n: { [n: number]: Base; }) => n; x341([d1, d2]); + var x342 = (n: {n: Base[]; } ) => n; x342({ n: [d1, d2] }); + var x343 = (n: (s: Base[]) => any) => n; x343(n => { var n: Base[]; return null; }); + var x344 = (n: Genric) => n; x344({ func: n => { return [d1, d2]; } }); + var x345 = function(n: () => Base[]) { }; x345(() => [d1, d2]); + var x346 = function(n: () => Base[]) { }; x346(function() { return [d1, d2] }); + var x347 = function(n: () => Base[]) { }; x347(function named() { return [d1, d2] }); + var x348 = function(n: { (): Base[]; }) { }; x348(() => [d1, d2]); + var x349 = function(n: { (): Base[]; }) { }; x349(function() { return [d1, d2] }); + var x350 = function(n: { (): Base[]; }) { }; x350(function named() { return [d1, d2] }); + var x351 = function(n: Base[]) { }; x351([d1, d2]); + var x352 = function(n: Array) { }; x352([d1, d2]); + var x353 = function(n: { [n: number]: Base; }) { }; x353([d1, d2]); + var x354 = function(n: {n: Base[]; } ) { }; x354({ n: [d1, d2] }); + var x355 = function(n: (s: Base[]) => any) { }; x355(n => { var n: Base[]; return null; }); + var x356 = function(n: Genric) { }; x356({ func: n => { return [d1, d2]; } }); \ No newline at end of file diff --git a/tests/baselines/reference/generatedContextualTyping.types b/tests/baselines/reference/generatedContextualTyping.types index fa9cd404a47c7..d926493015ac9 100644 --- a/tests/baselines/reference/generatedContextualTyping.types +++ b/tests/baselines/reference/generatedContextualTyping.types @@ -8,6 +8,7 @@ class Base { private p; } >Base : Base > : ^^^^ >p : any +> : ^^^ class Derived1 extends Base { private m; } >Derived1 : Derived1 @@ -15,6 +16,7 @@ class Derived1 extends Base { private m; } >Base : Base > : ^^^^ >m : any +> : ^^^ class Derived2 extends Base { private n; } >Derived2 : Derived2 @@ -22,6 +24,7 @@ class Derived2 extends Base { private n; } >Base : Base > : ^^^^ >n : any +> : ^^^ interface Genric { func(n: T[]); } >func : (n: T[]) => any diff --git a/tests/baselines/reference/ifDoWhileStatements.errors.txt b/tests/baselines/reference/ifDoWhileStatements.errors.txt new file mode 100644 index 0000000000000..8738d7709117f --- /dev/null +++ b/tests/baselines/reference/ifDoWhileStatements.errors.txt @@ -0,0 +1,237 @@ +ifDoWhileStatements.ts(56,5): error TS2869: This expression is always truthy. Did you mean to test something else? +ifDoWhileStatements.ts(57,8): error TS2869: This expression is always truthy. Did you mean to test something else? +ifDoWhileStatements.ts(58,13): error TS2869: This expression is always truthy. Did you mean to test something else? +ifDoWhileStatements.ts(60,5): error TS2870: This expression is always falsy. Did you mean to test something else? +ifDoWhileStatements.ts(61,8): error TS2870: This expression is always falsy. Did you mean to test something else? +ifDoWhileStatements.ts(62,13): error TS2870: This expression is always falsy. Did you mean to test something else? +ifDoWhileStatements.ts(64,5): error TS2869: This expression is always truthy. Did you mean to test something else? +ifDoWhileStatements.ts(65,8): error TS2869: This expression is always truthy. Did you mean to test something else? +ifDoWhileStatements.ts(66,13): error TS2869: This expression is always truthy. Did you mean to test something else? +ifDoWhileStatements.ts(68,5): error TS2869: This expression is always truthy. Did you mean to test something else? +ifDoWhileStatements.ts(69,8): error TS2869: This expression is always truthy. Did you mean to test something else? +ifDoWhileStatements.ts(70,13): error TS2869: This expression is always truthy. Did you mean to test something else? +ifDoWhileStatements.ts(72,5): error TS2869: This expression is always truthy. Did you mean to test something else? +ifDoWhileStatements.ts(73,8): error TS2869: This expression is always truthy. Did you mean to test something else? +ifDoWhileStatements.ts(74,13): error TS2869: This expression is always truthy. Did you mean to test something else? +ifDoWhileStatements.ts(76,5): error TS2869: This expression is always truthy. Did you mean to test something else? +ifDoWhileStatements.ts(77,8): error TS2869: This expression is always truthy. Did you mean to test something else? +ifDoWhileStatements.ts(78,13): error TS2869: This expression is always truthy. Did you mean to test something else? +ifDoWhileStatements.ts(80,5): error TS2869: This expression is always truthy. Did you mean to test something else? +ifDoWhileStatements.ts(81,8): error TS2869: This expression is always truthy. Did you mean to test something else? +ifDoWhileStatements.ts(82,13): error TS2869: This expression is always truthy. Did you mean to test something else? +ifDoWhileStatements.ts(84,5): error TS2869: This expression is always truthy. Did you mean to test something else? +ifDoWhileStatements.ts(85,8): error TS2869: This expression is always truthy. Did you mean to test something else? +ifDoWhileStatements.ts(86,13): error TS2869: This expression is always truthy. Did you mean to test something else? + + +==== ifDoWhileStatements.ts (24 errors) ==== + interface I { + id: number; + } + + class C implements I { + id: number; + name: string; + } + + class C2 extends C { + valid: boolean; + } + + class D{ + source: T; + recurse: D; + wrapped: D> + } + + function F(x: string): number { return 42; } + function F2(x: number): boolean { return x < 42; } + + module M { + export class A { + name: string; + } + + export function F2(x: number): string { return x.toString(); } + } + + module N { + export class A { + id: number; + } + + export function F2(x: number): string { return x.toString(); } + } + + // literals + if (true) { } + while (true) { } + do { }while(true) + + if (null) { } + while (null) { } + do { }while(null) + + if (undefined) { } + while (undefined) { } + do { }while(undefined) + + if (0.0) { } + while (0.0) { } + do { }while(0.0) + + if ('a string') { } + ~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + while ('a string') { } + ~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + do { }while('a string') + ~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + + if ('') { } + ~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? + while ('') { } + ~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? + do { }while('') + ~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? + + if (/[a-z]/) { } + ~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + while (/[a-z]/) { } + ~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + do { }while(/[a-z]/) + ~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + + if ([]) { } + ~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + while ([]) { } + ~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + do { }while([]) + ~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + + if ([1, 2]) { } + ~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + while ([1, 2]) { } + ~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + do { }while([1, 2]) + ~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + + if ({}) { } + ~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + while ({}) { } + ~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + do { }while({}) + ~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + + if ({ x: 1, y: 'a' }) { } + ~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + while ({ x: 1, y: 'a' }) { } + ~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + do { }while({ x: 1, y: 'a' }) + ~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + + if (() => 43) { } + ~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + while (() => 43) { } + ~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + do { }while(() => 43) + ~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + + if (new C()) { } + while (new C()) { } + do { }while(new C()) + + if (new D()) { } + while (new D()) { } + do { }while(new D()) + + // references + var a = true; + if (a) { } + while (a) { } + do { }while(a) + + var b = null; + if (b) { } + while (b) { } + do { }while(b) + + var c = undefined; + if (c) { } + while (c) { } + do { }while(c) + + var d = 0.0; + if (d) { } + while (d) { } + do { }while(d) + + var e = 'a string'; + if (e) { } + while (e) { } + do { }while(e) + + var f = ''; + if (f) { } + while (f) { } + do { }while(f) + + var g = /[a-z]/ + if (g) { } + while (g) { } + do { }while(g) + + var h = []; + if (h) { } + while (h) { } + do { }while(h) + + var i = [1, 2]; + if (i) { } + while (i) { } + do { }while(i) + + var j = {}; + if (j) { } + while (j) { } + do { }while(j) + + var k = { x: 1, y: 'a' }; + if (k) { } + while (k) { } + do { }while(k) + + function fn(x?: string): I { return null; } + if (fn()) { } + while (fn()) { } + do { }while(fn()) + + if (fn) { } + while (fn) { } + do { }while(fn) + + + \ No newline at end of file diff --git a/tests/baselines/reference/ifDoWhileStatements.types b/tests/baselines/reference/ifDoWhileStatements.types index b97dda14f7308..7a7cf04fa2bfd 100644 --- a/tests/baselines/reference/ifDoWhileStatements.types +++ b/tests/baselines/reference/ifDoWhileStatements.types @@ -360,29 +360,37 @@ do { }while(a) var b = null; >b : any +> : ^^^ if (b) { } >b : any +> : ^^^ while (b) { } >b : any +> : ^^^ do { }while(b) >b : any +> : ^^^ var c = undefined; >c : any +> : ^^^ >undefined : undefined > : ^^^^^^^^^ if (c) { } >c : any +> : ^^^ while (c) { } >c : any +> : ^^^ do { }while(c) >c : any +> : ^^^ var d = 0.0; >d : number diff --git a/tests/baselines/reference/initializersWidened.errors.txt b/tests/baselines/reference/initializersWidened.errors.txt new file mode 100644 index 0000000000000..3ad7491f03ba9 --- /dev/null +++ b/tests/baselines/reference/initializersWidened.errors.txt @@ -0,0 +1,33 @@ +initializersWidened.ts(20,10): error TS2870: This expression is always falsy. Did you mean to test something else? +initializersWidened.ts(24,10): error TS2870: This expression is always falsy. Did you mean to test something else? + + +==== initializersWidened.ts (2 errors) ==== + // these are widened to any at the point of assignment + + var x1 = null; + var y1 = undefined; + var z1 = void 0; + + // these are not widened + + var x2: null; + var y2: undefined; + + var x3: null = null; + var y3: undefined = undefined; + var z3: undefined = void 0; + + // widen only when all constituents of union are widening + + var x4 = null || null; + var y4 = undefined || undefined; + var z4 = void 0 || void 0; + ~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? + + var x5 = null || x2; + var y5 = undefined || y2; + var z5 = void 0 || y2; + ~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? \ No newline at end of file diff --git a/tests/baselines/reference/initializersWidened.types b/tests/baselines/reference/initializersWidened.types index e4addaf4531c5..485a47c2eee92 100644 --- a/tests/baselines/reference/initializersWidened.types +++ b/tests/baselines/reference/initializersWidened.types @@ -5,14 +5,17 @@ var x1 = null; >x1 : any +> : ^^^ var y1 = undefined; >y1 : any +> : ^^^ >undefined : undefined > : ^^^^^^^^^ var z1 = void 0; >z1 : any +> : ^^^ >void 0 : undefined > : ^^^^^^^^^ >0 : 0 @@ -50,11 +53,13 @@ var z3: undefined = void 0; var x4 = null || null; >x4 : any +> : ^^^ >null || null : null > : ^^^^ var y4 = undefined || undefined; >y4 : any +> : ^^^ >undefined || undefined : undefined > : ^^^^^^^^^ >undefined : undefined @@ -64,6 +69,7 @@ var y4 = undefined || undefined; var z4 = void 0 || void 0; >z4 : any +> : ^^^ >void 0 || void 0 : undefined > : ^^^^^^^^^ >void 0 : undefined diff --git a/tests/baselines/reference/logicalNotOperatorWithBooleanType.errors.txt b/tests/baselines/reference/logicalNotOperatorWithBooleanType.errors.txt index 3c94e6e5b05d2..2feb09506c396 100644 --- a/tests/baselines/reference/logicalNotOperatorWithBooleanType.errors.txt +++ b/tests/baselines/reference/logicalNotOperatorWithBooleanType.errors.txt @@ -1,7 +1,8 @@ +logicalNotOperatorWithBooleanType.ts(21,25): error TS2869: This expression is always truthy. Did you mean to test something else? logicalNotOperatorWithBooleanType.ts(36,1): error TS2695: Left side of comma operator is unused and has no side effects. -==== logicalNotOperatorWithBooleanType.ts (1 errors) ==== +==== logicalNotOperatorWithBooleanType.ts (2 errors) ==== // ! operator on boolean type var BOOLEAN: boolean; @@ -23,6 +24,8 @@ logicalNotOperatorWithBooleanType.ts(36,1): error TS2695: Left side of comma ope // boolean type literal var ResultIsBoolean2 = !true; var ResultIsBoolean3 = !{ x: true, y: false }; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? // boolean type expressions var ResultIsBoolean4 = !objA.a; diff --git a/tests/baselines/reference/logicalNotOperatorWithNumberType.errors.txt b/tests/baselines/reference/logicalNotOperatorWithNumberType.errors.txt index b5202f7b5c9d6..cd854fcd77cb6 100644 --- a/tests/baselines/reference/logicalNotOperatorWithNumberType.errors.txt +++ b/tests/baselines/reference/logicalNotOperatorWithNumberType.errors.txt @@ -1,7 +1,9 @@ +logicalNotOperatorWithNumberType.ts(23,25): error TS2869: This expression is always truthy. Did you mean to test something else? +logicalNotOperatorWithNumberType.ts(24,25): error TS2869: This expression is always truthy. Did you mean to test something else? logicalNotOperatorWithNumberType.ts(45,1): error TS2695: Left side of comma operator is unused and has no side effects. -==== logicalNotOperatorWithNumberType.ts (1 errors) ==== +==== logicalNotOperatorWithNumberType.ts (3 errors) ==== // ! operator on number type var NUMBER: number; var NUMBER1: number[] = [1, 2]; @@ -25,7 +27,11 @@ logicalNotOperatorWithNumberType.ts(45,1): error TS2695: Left side of comma oper // number type literal var ResultIsBoolean3 = !1; var ResultIsBoolean4 = !{ x: 1, y: 2}; + ~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? var ResultIsBoolean5 = !{ x: 1, y: (n: number) => { return n; } }; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? // number type expressions var ResultIsBoolean6 = !objA.a; diff --git a/tests/baselines/reference/logicalNotOperatorWithStringType.errors.txt b/tests/baselines/reference/logicalNotOperatorWithStringType.errors.txt index 6f3272778790a..77f74d0561537 100644 --- a/tests/baselines/reference/logicalNotOperatorWithStringType.errors.txt +++ b/tests/baselines/reference/logicalNotOperatorWithStringType.errors.txt @@ -1,7 +1,11 @@ +logicalNotOperatorWithStringType.ts(22,25): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalNotOperatorWithStringType.ts(23,25): error TS2869: This expression is always truthy. Did you mean to test something else? +logicalNotOperatorWithStringType.ts(24,25): error TS2869: This expression is always truthy. Did you mean to test something else? +logicalNotOperatorWithStringType.ts(40,2): error TS2870: This expression is always falsy. Did you mean to test something else? logicalNotOperatorWithStringType.ts(44,1): error TS2695: Left side of comma operator is unused and has no side effects. -==== logicalNotOperatorWithStringType.ts (1 errors) ==== +==== logicalNotOperatorWithStringType.ts (5 errors) ==== // ! operator on string type var STRING: string; var STRING1: string[] = ["", "abc"]; @@ -24,8 +28,14 @@ logicalNotOperatorWithStringType.ts(44,1): error TS2695: Left side of comma oper // string type literal var ResultIsBoolean3 = !""; + ~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var ResultIsBoolean4 = !{ x: "", y: "" }; + ~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? var ResultIsBoolean5 = !{ x: "", y: (s: string) => { return s; } }; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? // string type expressions var ResultIsBoolean6 = !objA.a; @@ -42,6 +52,8 @@ logicalNotOperatorWithStringType.ts(44,1): error TS2695: Left side of comma oper // miss assignment operators !""; + ~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? !STRING; !STRING1; !foo(); diff --git a/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.errors.txt b/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.errors.txt index 2b2e4b701852f..94c9265e6c098 100644 --- a/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.errors.txt +++ b/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.errors.txt @@ -1,14 +1,17 @@ +logicalOrExpressionIsContextuallyTyped.ts(6,24): error TS2869: This expression is always truthy. Did you mean to test something else? logicalOrExpressionIsContextuallyTyped.ts(6,33): error TS2322: Type '{ a: string; b: number; } | { a: string; b: boolean; }' is not assignable to type '{ a: string; }'. Object literal may only specify known properties, and 'b' does not exist in type '{ a: string; }'. -==== logicalOrExpressionIsContextuallyTyped.ts (1 errors) ==== +==== logicalOrExpressionIsContextuallyTyped.ts (2 errors) ==== // The || operator permits the operands to be of any type. // If the || expression is contextually typed, the operands are contextually typed by the // same type and the result is of the best common type of the contextual type and the two // operand types. var r: { a: string } = { a: '', b: 123 } || { a: '', b: true }; + ~~~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? ~ !!! error TS2322: Type '{ a: string; b: number; } | { a: string; b: boolean; }' is not assignable to type '{ a: string; }'. !!! error TS2322: Object literal may only specify known properties, and 'b' does not exist in type '{ a: string; }'. \ No newline at end of file diff --git a/tests/baselines/reference/mergeSameGenericParentMethodPropUnions-100.errors.txt b/tests/baselines/reference/mergeSameGenericParentMethodPropUnions-100.errors.txt new file mode 100644 index 0000000000000..59f9311e35fd0 --- /dev/null +++ b/tests/baselines/reference/mergeSameGenericParentMethodPropUnions-100.errors.txt @@ -0,0 +1,98 @@ +-incompasig-110.ts(9,20): error TS2349: This expression is not callable. + Each member of the union type '{ (cb: (x: number) => number): number[]; (cb: (x: number) => U): U[]; } | { (cb: (x: string) => string): string[]; (cb: (x: string) => U): U[]; }' has signatures, but none of those signatures are compatible with each other. +-incompasig-110.ts(9,22): error TS7006: Parameter 'x' implicitly has an 'any' type. +-incompasig-111.ts(9,20): error TS2349: This expression is not callable. + Each member of the union type '{ (cb: (a: number, x: number) => number): number[]; (cb: (a: U, x: number) => U, init: U): U[]; } | { (cb: (a: bigint, x: bigint) => bigint): bigint[]; (cb: (a: U, x: bigint) => U, init: U): U[]; }' has signatures, but none of those signatures are compatible with each other. +-incompasig-111.ts(9,33): error TS7006: Parameter 'x' implicitly has an 'any' type. +-incompasig-200.ts(7,11): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'never'. + Type 'string' is not assignable to type 'never'. +-incompasig-200.ts(9,8): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'never'. + Type 'string' is not assignable to type 'never'. +-incompasig-200.ts(11,11): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'never'. + Type 'string' is not assignable to type 'never'. +-incompasig-200.ts(13,14): error TS2769: No overload matches this call. + Overload 1 of 3, '(start: number, deleteCount: number, ...items: string[]): string[] | number[]', gave the following error. + Argument of type 'string | number' is not assignable to parameter of type 'string'. + Type 'number' is not assignable to type 'string'. + Overload 2 of 3, '(start: number, deleteCount: number, ...items: number[]): string[] | number[]', gave the following error. + Argument of type 'string | number' is not assignable to parameter of type 'number'. + Type 'string' is not assignable to type 'number'. + + +==== -incompasig-200.ts (4 errors) ==== + namespace ns4 { + + declare var y: Array|Array; + + declare const a: number|string; + + y.indexOf(a); + ~ +!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'never'. +!!! error TS2345: Type 'string' is not assignable to type 'never'. + + y.push(a); + ~ +!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'never'. +!!! error TS2345: Type 'string' is not assignable to type 'never'. + + y.unshift(a); + ~ +!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'never'. +!!! error TS2345: Type 'string' is not assignable to type 'never'. + + y.splice(1,1,a); + ~ +!!! error TS2769: No overload matches this call. +!!! error TS2769: Overload 1 of 3, '(start: number, deleteCount: number, ...items: string[]): string[] | number[]', gave the following error. +!!! error TS2769: Argument of type 'string | number' is not assignable to parameter of type 'string'. +!!! error TS2769: Type 'number' is not assignable to type 'string'. +!!! error TS2769: Overload 2 of 3, '(start: number, deleteCount: number, ...items: number[]): string[] | number[]', gave the following error. +!!! error TS2769: Argument of type 'string | number' is not assignable to parameter of type 'number'. +!!! error TS2769: Type 'string' is not assignable to type 'number'. + + } + + + /**********************/ +==== -incompasig-110.ts (2 errors) ==== + namespace ns0 { + + interface Test110 { + f(cb:(x:T)=>T):T[]; + f(cb:(x:T)=>U):U[]; + } + + declare const arr: Test110 | Test110; + const result = arr.f(x => x); + ~ +!!! error TS2349: This expression is not callable. +!!! error TS2349: Each member of the union type '{ (cb: (x: number) => number): number[]; (cb: (x: number) => U): U[]; } | { (cb: (x: string) => string): string[]; (cb: (x: string) => U): U[]; }' has signatures, but none of those signatures are compatible with each other. + ~ +!!! error TS7006: Parameter 'x' implicitly has an 'any' type. + + } + + + /**********************/ +==== -incompasig-111.ts (2 errors) ==== + namespace ns1 { + + interface Test111 { + f(cb:(a:T, x:T)=>T):T[]; + f(cb:(a:U, x:T)=>U,init:U):U[]; + } + + declare const arr: Test111 | Test111; + const result = arr.f((a:bigint, x) => a * BigInt(x), 1n); + ~ +!!! error TS2349: This expression is not callable. +!!! error TS2349: Each member of the union type '{ (cb: (a: number, x: number) => number): number[]; (cb: (a: U, x: number) => U, init: U): U[]; } | { (cb: (a: bigint, x: bigint) => bigint): bigint[]; (cb: (a: U, x: bigint) => U, init: U): U[]; }' has signatures, but none of those signatures are compatible with each other. + ~ +!!! error TS7006: Parameter 'x' implicitly has an 'any' type. + + } + + + + \ No newline at end of file diff --git a/tests/baselines/reference/nestedIfStatement.errors.txt b/tests/baselines/reference/nestedIfStatement.errors.txt new file mode 100644 index 0000000000000..13eddc2e8334c --- /dev/null +++ b/tests/baselines/reference/nestedIfStatement.errors.txt @@ -0,0 +1,15 @@ +nestedIfStatement.ts(3,12): error TS2869: This expression is always truthy. Did you mean to test something else? +nestedIfStatement.ts(4,12): error TS2869: This expression is always truthy. Did you mean to test something else? + + +==== nestedIfStatement.ts (2 errors) ==== + if (0) { + } else if (1) { + } else if (2) { + ~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + } else if (3) { + ~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + } else { + } \ No newline at end of file diff --git a/tests/baselines/reference/noImplicitAnyForIn.errors.txt b/tests/baselines/reference/noImplicitAnyForIn.errors.txt index 3354ac3293612..d4cf8de1e3f57 100644 --- a/tests/baselines/reference/noImplicitAnyForIn.errors.txt +++ b/tests/baselines/reference/noImplicitAnyForIn.errors.txt @@ -3,10 +3,11 @@ noImplicitAnyForIn.ts(7,18): error TS7053: Element implicitly has an 'any' type noImplicitAnyForIn.ts(14,18): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'. No index signature with a parameter of type 'string' was found on type '{}'. noImplicitAnyForIn.ts(28,5): error TS7005: Variable 'n' implicitly has an 'any[][]' type. +noImplicitAnyForIn.ts(28,9): error TS2869: This expression is always truthy. Did you mean to test something else? noImplicitAnyForIn.ts(30,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. -==== noImplicitAnyForIn.ts (4 errors) ==== +==== noImplicitAnyForIn.ts (5 errors) ==== var x: {}[] = [[1, 2, 3], ["hello"]]; for (var i in x) { @@ -43,6 +44,8 @@ noImplicitAnyForIn.ts(30,6): error TS2405: The left-hand side of a 'for...in' st var n = [[]] || []; ~ !!! error TS7005: Variable 'n' implicitly has an 'any[][]' type. + ~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? for (n[idx++] in m); ~~~~~~~~ diff --git a/tests/baselines/reference/nullishCoalescingOperator1.errors.txt b/tests/baselines/reference/nullishCoalescingOperator1.errors.txt new file mode 100644 index 0000000000000..c14b4fe0b3b34 --- /dev/null +++ b/tests/baselines/reference/nullishCoalescingOperator1.errors.txt @@ -0,0 +1,71 @@ +nullishCoalescingOperator1.ts(59,5): error TS2871: Using ?? on this expression appears unintentional because it always evaluates to the same nullishness. + + +==== nullishCoalescingOperator1.ts (1 errors) ==== + declare const a1: string | undefined | null + declare const a2: string | undefined | null + declare const a3: string | undefined | null + declare const a4: string | undefined | null + + declare const b1: number | undefined | null + declare const b2: number | undefined | null + declare const b3: number | undefined | null + declare const b4: number | undefined | null + + declare const c1: boolean | undefined | null + declare const c2: boolean | undefined | null + declare const c3: boolean | undefined | null + declare const c4: boolean | undefined | null + + interface I { a: string } + declare const d1: I | undefined | null + declare const d2: I | undefined | null + declare const d3: I | undefined | null + declare const d4: I | undefined | null + + const aa1 = a1 ?? 'whatever'; + const aa2 = a2 ?? 'whatever'; + const aa3 = a3 ?? 'whatever'; + const aa4 = a4 ?? 'whatever'; + + const bb1 = b1 ?? 1; + const bb2 = b2 ?? 1; + const bb3 = b3 ?? 1; + const bb4 = b4 ?? 1; + + const cc1 = c1 ?? true; + const cc2 = c2 ?? true; + const cc3 = c3 ?? true; + const cc4 = c4 ?? true; + + const dd1 = d1 ?? {b: 1}; + const dd2 = d2 ?? {b: 1}; + const dd3 = d3 ?? {b: 1}; + const dd4 = d4 ?? {b: 1}; + + // Repro from #34635 + + declare function foo(): void; + + const maybeBool = false; + + if (!(maybeBool ?? true)) { + foo(); + } + + if (maybeBool ?? true) { + foo(); + } + else { + foo(); + } + + if (false ?? true) { + ~~~~~ +!!! error TS2871: Using ?? on this expression appears unintentional because it always evaluates to the same nullishness. + foo(); + } + else { + foo(); + } + \ No newline at end of file diff --git a/tests/baselines/reference/nullishCoalescingOperator7.errors.txt b/tests/baselines/reference/nullishCoalescingOperator7.errors.txt new file mode 100644 index 0000000000000..295b9590be99c --- /dev/null +++ b/tests/baselines/reference/nullishCoalescingOperator7.errors.txt @@ -0,0 +1,24 @@ +nullishCoalescingOperator7.ts(6,19): error TS2869: This expression is always truthy. Did you mean to test something else? +nullishCoalescingOperator7.ts(7,19): error TS2869: This expression is always truthy. Did you mean to test something else? +nullishCoalescingOperator7.ts(10,23): error TS2869: This expression is always truthy. Did you mean to test something else? + + +==== nullishCoalescingOperator7.ts (3 errors) ==== + declare const a: string | undefined; + declare const b: string | undefined; + declare const c: string | undefined; + + const foo1 = a ? 1 : 2; + const foo2 = a ?? 'foo' ? 1 : 2; + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + const foo3 = a ?? 'foo' ? (b ?? 'bar') : (c ?? 'baz'); + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + + function f () { + const foo4 = a ?? 'foo' ? b ?? 'bar' : c ?? 'baz'; + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + } + \ No newline at end of file diff --git a/tests/baselines/reference/parserArrowFunctionExpression3.errors.txt b/tests/baselines/reference/parserArrowFunctionExpression3.errors.txt index 7895b50bdc031..0cd338eef3e50 100644 --- a/tests/baselines/reference/parserArrowFunctionExpression3.errors.txt +++ b/tests/baselines/reference/parserArrowFunctionExpression3.errors.txt @@ -1,13 +1,16 @@ parserArrowFunctionExpression3.ts(1,1): error TS2304: Cannot find name 'a'. +parserArrowFunctionExpression3.ts(1,6): error TS2869: This expression is always truthy. Did you mean to test something else? parserArrowFunctionExpression3.ts(1,16): error TS1005: ')' expected. parserArrowFunctionExpression3.ts(1,19): error TS2304: Cannot find name 'a'. parserArrowFunctionExpression3.ts(1,20): error TS1005: ';' expected. -==== parserArrowFunctionExpression3.ts (4 errors) ==== +==== parserArrowFunctionExpression3.ts (5 errors) ==== a = (() => { } || a) ~ !!! error TS2304: Cannot find name 'a'. + ~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? ~~ !!! error TS1005: ')' expected. ~ diff --git a/tests/baselines/reference/parserRegularExpression3.errors.txt b/tests/baselines/reference/parserRegularExpression3.errors.txt index 4241bebdaa27e..2f842db1ef1b2 100644 --- a/tests/baselines/reference/parserRegularExpression3.errors.txt +++ b/tests/baselines/reference/parserRegularExpression3.errors.txt @@ -1,7 +1,10 @@ parserRegularExpression3.ts(1,1): error TS2304: Cannot find name 'Foo'. +parserRegularExpression3.ts(1,6): error TS2869: This expression is always truthy. Did you mean to test something else? -==== parserRegularExpression3.ts (1 errors) ==== +==== parserRegularExpression3.ts (2 errors) ==== Foo(!/(\\?|&)adurl=/); ~~~ -!!! error TS2304: Cannot find name 'Foo'. \ No newline at end of file +!!! error TS2304: Cannot find name 'Foo'. + ~~~~~~~~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? \ No newline at end of file diff --git a/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.errors.txt b/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.errors.txt new file mode 100644 index 0000000000000..4bae3c1aa1868 --- /dev/null +++ b/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.errors.txt @@ -0,0 +1,35 @@ +prefixUnaryOperatorsOnExportedVariables.ts(19,5): error TS2870: This expression is always falsy. Did you mean to test something else? + + +==== prefixUnaryOperatorsOnExportedVariables.ts (1 errors) ==== + export var x = false; + export var y = 1; + if (!x) { + + } + + if (+x) { + + } + + if (-x) { + + } + + if (~x) { + + } + + if (void x) { + ~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? + + } + + if (typeof x) { + + } + + if (++y) { + + } \ No newline at end of file diff --git a/tests/baselines/reference/primitiveMembers.errors.txt b/tests/baselines/reference/primitiveMembers.errors.txt index 2390727396068..4bd235fb0b5f0 100644 --- a/tests/baselines/reference/primitiveMembers.errors.txt +++ b/tests/baselines/reference/primitiveMembers.errors.txt @@ -1,9 +1,10 @@ primitiveMembers.ts(5,3): error TS2339: Property 'toBAZ' does not exist on type 'number'. primitiveMembers.ts(11,1): error TS2322: Type 'Number' is not assignable to type 'number'. 'number' is a primitive, but 'Number' is a wrapper object. Prefer using 'number' when possible. +primitiveMembers.ts(21,10): error TS2869: This expression is always truthy. Did you mean to test something else? -==== primitiveMembers.ts (2 errors) ==== +==== primitiveMembers.ts (3 errors) ==== var x = 5; var r = /yo/; r.source; @@ -30,6 +31,8 @@ primitiveMembers.ts(11,1): error TS2322: Type 'Number' is not assignable to type var b: Boolean = true; var n3 = 5 || {}; + ~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? class baz { public bar(): void { }; } diff --git a/tests/baselines/reference/shebangError.errors.txt b/tests/baselines/reference/shebangError.errors.txt index 43213c29fc2c1..0f6c1d9aafb19 100644 --- a/tests/baselines/reference/shebangError.errors.txt +++ b/tests/baselines/reference/shebangError.errors.txt @@ -1,17 +1,20 @@ shebangError.ts(2,1): error TS18026: '#!' can only be used at the start of a file. shebangError.ts(2,2): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +shebangError.ts(2,3): error TS2869: This expression is always truthy. Did you mean to test something else? shebangError.ts(2,12): error TS2304: Cannot find name 'env'. shebangError.ts(2,16): error TS1005: ';' expected. shebangError.ts(2,16): error TS2304: Cannot find name 'node'. -==== shebangError.ts (5 errors) ==== +==== shebangError.ts (6 errors) ==== var foo = 'Shebang is only allowed on the first line'; #!/usr/bin/env node ~~ !!! error TS18026: '#!' can only be used at the start of a file. ~~~~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. + ~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? ~~~ !!! error TS2304: Cannot find name 'env'. ~~~~ diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt index f294ce932fc38..eeb6cb9a0ce78 100644 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt @@ -1,18 +1,22 @@ stringLiteralsWithSwitchStatements03.ts(10,10): error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. Type '"baz"' is not comparable to type '"foo"'. +stringLiteralsWithSwitchStatements03.ts(10,34): error TS2869: This expression is always truthy. Did you mean to test something else? stringLiteralsWithSwitchStatements03.ts(12,10): error TS2678: Type '"bar"' is not comparable to type '"foo"'. stringLiteralsWithSwitchStatements03.ts(14,10): error TS2678: Type '"baz"' is not comparable to type '"foo"'. stringLiteralsWithSwitchStatements03.ts(14,11): error TS2695: Left side of comma operator is unused and has no side effects. stringLiteralsWithSwitchStatements03.ts(14,11): error TS2695: Left side of comma operator is unused and has no side effects. +stringLiteralsWithSwitchStatements03.ts(18,12): error TS2869: This expression is always truthy. Did you mean to test something else? stringLiteralsWithSwitchStatements03.ts(20,10): error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. Type '"baz"' is not comparable to type '"foo"'. +stringLiteralsWithSwitchStatements03.ts(20,12): error TS2869: This expression is always truthy. Did you mean to test something else? stringLiteralsWithSwitchStatements03.ts(22,10): error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. Type '"baz"' is not comparable to type '"foo"'. +stringLiteralsWithSwitchStatements03.ts(23,10): error TS2869: This expression is always truthy. Did you mean to test something else? stringLiteralsWithSwitchStatements03.ts(23,10): error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. Type '"baz"' is not comparable to type '"foo"'. -==== stringLiteralsWithSwitchStatements03.ts (8 errors) ==== +==== stringLiteralsWithSwitchStatements03.ts (12 errors) ==== let x: "foo"; let y: "foo" | "bar"; let z: "bar"; @@ -26,6 +30,8 @@ stringLiteralsWithSwitchStatements03.ts(23,10): error TS2678: Type '"bar" | "baz ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. !!! error TS2678: Type '"baz"' is not comparable to type '"foo"'. + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? break; case (("bar")): ~~~~~~~~~ @@ -42,17 +48,23 @@ stringLiteralsWithSwitchStatements03.ts(23,10): error TS2678: Type '"bar" | "baz y; break; case (("foo" || ("bar"))): + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? break; case (("bar" || ("baz"))): ~~~~~~~~~~~~~~~~~~~~ !!! error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. !!! error TS2678: Type '"baz"' is not comparable to type '"foo"'. + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? break; case z || "baz": ~~~~~~~~~~ !!! error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. !!! error TS2678: Type '"baz"' is not comparable to type '"foo"'. case "baz" || z: + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? ~~~~~~~~~~ !!! error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. !!! error TS2678: Type '"baz"' is not comparable to type '"foo"'. diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements04.errors.txt b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.errors.txt index 824ecf68923c0..c25a691e88ac7 100644 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements04.errors.txt +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.errors.txt @@ -3,9 +3,14 @@ stringLiteralsWithSwitchStatements04.ts(9,10): error TS2695: Left side of comma stringLiteralsWithSwitchStatements04.ts(11,10): error TS2695: Left side of comma operator is unused and has no side effects. stringLiteralsWithSwitchStatements04.ts(11,10): error TS2678: Type '"baz"' is not comparable to type '"foo" | "bar"'. stringLiteralsWithSwitchStatements04.ts(13,10): error TS2695: Left side of comma operator is unused and has no side effects. +stringLiteralsWithSwitchStatements04.ts(15,10): error TS2869: This expression is always truthy. Did you mean to test something else? +stringLiteralsWithSwitchStatements04.ts(17,10): error TS2869: This expression is always truthy. Did you mean to test something else? +stringLiteralsWithSwitchStatements04.ts(17,20): error TS2869: This expression is always truthy. Did you mean to test something else? +stringLiteralsWithSwitchStatements04.ts(19,10): error TS2869: This expression is always truthy. Did you mean to test something else? +stringLiteralsWithSwitchStatements04.ts(19,20): error TS2869: This expression is always truthy. Did you mean to test something else? -==== stringLiteralsWithSwitchStatements04.ts (5 errors) ==== +==== stringLiteralsWithSwitchStatements04.ts (10 errors) ==== let x: "foo"; let y: "foo" | "bar"; @@ -31,10 +36,20 @@ stringLiteralsWithSwitchStatements04.ts(13,10): error TS2695: Left side of comma !!! error TS2695: Left side of comma operator is unused and has no side effects. break; case "baz" && "bar": + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? break; case "baz" && ("foo" || "bar"): + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? break; case "bar" && ("baz" || "bar"): + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? + ~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? break; } \ No newline at end of file diff --git a/tests/baselines/reference/symbolType11.errors.txt b/tests/baselines/reference/symbolType11.errors.txt new file mode 100644 index 0000000000000..e3ee4da22f187 --- /dev/null +++ b/tests/baselines/reference/symbolType11.errors.txt @@ -0,0 +1,13 @@ +symbolType11.ts(7,2): error TS2869: This expression is always truthy. Did you mean to test something else? + + +==== symbolType11.ts (1 errors) ==== + var s = Symbol.for("logical"); + s && s; + s && []; + 0 && s; + s || s; + s || 1; + ({}) || s; + ~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardsInIfStatement.errors.txt b/tests/baselines/reference/typeGuardsInIfStatement.errors.txt index 25270e619d4a7..dd9b5577bfbda 100644 --- a/tests/baselines/reference/typeGuardsInIfStatement.errors.txt +++ b/tests/baselines/reference/typeGuardsInIfStatement.errors.txt @@ -1,7 +1,8 @@ +typeGuardsInIfStatement.ts(120,17): error TS2869: This expression is always truthy. Did you mean to test something else? typeGuardsInIfStatement.ts(139,17): error TS2339: Property 'toString' does not exist on type 'never'. -==== typeGuardsInIfStatement.ts (1 errors) ==== +==== typeGuardsInIfStatement.ts (2 errors) ==== // In the true branch statement of an 'if' statement, // the type of a variable or parameter is narrowed by any type guard in the 'if' condition when true. // In the false branch statement of an 'if' statement, @@ -122,6 +123,8 @@ typeGuardsInIfStatement.ts(139,17): error TS2339: Property 'toString' does not e ? ( // change value of x x = 10 && x.toString() // number | boolean | string + ~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? ) : ( // do not change value diff --git a/tests/baselines/reference/voidAsOperator.errors.txt b/tests/baselines/reference/voidAsOperator.errors.txt new file mode 100644 index 0000000000000..ea9a3ae16b367 --- /dev/null +++ b/tests/baselines/reference/voidAsOperator.errors.txt @@ -0,0 +1,15 @@ +voidAsOperator.ts(1,6): error TS2870: This expression is always falsy. Did you mean to test something else? + + +==== voidAsOperator.ts (1 errors) ==== + if (!void 0 !== true) { + ~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? + + } + + //CHECK#2 + if (!null !== true) { + + } + \ No newline at end of file diff --git a/tests/baselines/reference/witness.errors.txt b/tests/baselines/reference/witness.errors.txt index 00b85e614abd1..25ba45efaf4f3 100644 --- a/tests/baselines/reference/witness.errors.txt +++ b/tests/baselines/reference/witness.errors.txt @@ -12,14 +12,16 @@ witness.ts(33,5): error TS2403: Subsequent variable declarations must have the s witness.ts(37,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'as1' must be of type 'any', but here has type 'number'. witness.ts(39,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'as2' must be of type 'any', but here has type 'number'. witness.ts(43,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'cnd1' must be of type 'any', but here has type 'number'. +witness.ts(50,11): error TS2870: This expression is always falsy. Did you mean to test something else? witness.ts(57,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'and1' must be of type 'any', but here has type 'string'. +witness.ts(58,12): error TS2870: This expression is always falsy. Did you mean to test something else? witness.ts(68,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'fnCallResult' must be of type 'never', but here has type 'any'. witness.ts(110,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'propAcc1' must be of type 'any', but here has type '{ m: any; }'. witness.ts(121,14): error TS2729: Property 'n' is used before its initialization. witness.ts(128,19): error TS2729: Property 'q' is used before its initialization. -==== witness.ts (19 errors) ==== +==== witness.ts (21 errors) ==== // Initializers var varInit = varInit; // any var pInit: any; @@ -105,6 +107,8 @@ witness.ts(128,19): error TS2729: Property 'q' is used before its initialization var or1 = or1 || ''; var or1: any; var or2 = '' || or2; + ~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var or2: any; var or3 = or3 || or3; var or3: any; @@ -116,6 +120,8 @@ witness.ts(128,19): error TS2729: Property 'q' is used before its initialization !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'and1' must be of type 'any', but here has type 'string'. !!! related TS6203 witness.ts:56:5: 'and1' was also declared here. var and2 = '' && and2; + ~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var and2: any; var and3 = and3 && and3; var and3: any; From 263a967aa78587ddec0df5a6c9f7204088cf0de9 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 9 Jul 2024 21:53:47 -0700 Subject: [PATCH 02/12] Lint/format --- src/compiler/checker.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a4735e4658802..5f4f1bccf73ba 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -898,6 +898,7 @@ import { NodeWithTypeArguments, NonNullChain, NonNullExpression, + NoSubstitutionTemplateLiteral, not, noTruncationMaximumTruncationLength, NumberLiteralType, @@ -1114,7 +1115,6 @@ import { WideningContext, WithStatement, YieldExpression, - NoSubstitutionTemplateLiteral, } from "./_namespaces/ts.js"; import * as moduleSpecifiers from "./_namespaces/ts.moduleSpecifiers.js"; import * as performance from "./_namespaces/ts.performance.js"; @@ -44231,7 +44231,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { error(node, Diagnostics.An_expression_of_type_void_cannot_be_tested_for_truthiness); } - let alwaysTruthy: boolean | undefined = undefined; + let alwaysTruthy: boolean | undefined; switch (node.kind) { case SyntaxKind.NumericLiteral: // Allow `while(0)` or `while(1)` @@ -44258,10 +44258,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } if (alwaysTruthy !== undefined) { - error(node, + error( + node, alwaysTruthy ? Diagnostics.This_expression_is_always_truthy_Did_you_mean_to_test_something_else : - Diagnostics.This_expression_is_always_falsy_Did_you_mean_to_test_something_else); + Diagnostics.This_expression_is_always_falsy_Did_you_mean_to_test_something_else, + ); } return type; From 02353fc6071e793db04ae2142b05448aceda45b8 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 10 Jul 2024 10:29:30 -0700 Subject: [PATCH 03/12] Fix-ups --- src/compiler/checker.ts | 90 +++++++++++------ src/compiler/types.ts | 8 ++ src/compiler/utilities.ts | 2 +- tests/baselines/reference/api/typescript.d.ts | 1 + ...alOperatorConditionIsObjectType.errors.txt | 48 ++++----- ...ionalOperatorConditoinIsAnyType.errors.txt | 14 ++- .../contextuallyTypeLogicalAnd03.errors.txt | 8 +- ...declFileTypeAnnotationParenType.errors.txt | 8 +- .../fatarrowfunctionsOptionalArgs.errors.txt | 4 +- .../generatedContextualTyping.errors.txt | 50 +++++++++- .../reference/ifDoWhileStatements.errors.txt | 11 ++- .../reference/initializersWidened.errors.txt | 8 +- ...logicalAndOperatorWithEveryType.errors.txt | 34 ++++++- ...icalNotOperatorWithAnyOtherType.errors.txt | 5 +- .../logicalOrOperatorWithEveryType.errors.txt | 34 ++++++- .../parserArrowFunctionExpression3.errors.txt | 4 +- .../reference/predicateSemantics.errors.txt | 29 ++++++ .../baselines/reference/predicateSemantics.js | 37 +++++++ .../reference/predicateSemantics.symbols | 35 +++++++ .../reference/predicateSemantics.types | 97 +++++++++++++++++++ .../reference/symbolType11.errors.txt | 4 +- tests/cases/compiler/predicateSemantics.ts | 19 ++++ 22 files changed, 470 insertions(+), 80 deletions(-) create mode 100644 tests/baselines/reference/predicateSemantics.errors.txt create mode 100644 tests/baselines/reference/predicateSemantics.js create mode 100644 tests/baselines/reference/predicateSemantics.symbols create mode 100644 tests/baselines/reference/predicateSemantics.types create mode 100644 tests/cases/compiler/predicateSemantics.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5f4f1bccf73ba..64bb60ecedf10 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1115,6 +1115,9 @@ import { WideningContext, WithStatement, YieldExpression, + PredicateSemantics, + OuterExpression, + isBinaryLogicalOperator, } from "./_namespaces/ts.js"; import * as moduleSpecifiers from "./_namespaces/ts.moduleSpecifiers.js"; import * as performance from "./_namespaces/ts.performance.js"; @@ -39484,7 +39487,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (operator === SyntaxKind.AmpersandAmpersandToken || isIfStatement(parent)) { checkTestingKnownTruthyCallableOrAwaitableOrEnumMemberType(node.left, leftType, isIfStatement(parent) ? parent.thenStatement : undefined); } - checkTruthinessOfType(leftType, node.left); + if (isBinaryLogicalOperator(operator)) { + checkTruthinessOfType(leftType, node.left); + } } } } @@ -39561,24 +39566,21 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } const leftTarget = skipOuterExpressions(left, OuterExpressionKinds.All); - if (hasStaticNullishness(leftTarget)) { + if (getSyntacticNullishnessSemantics(leftTarget) !== PredicateSemantics.Sometimes) { error(leftTarget, Diagnostics.Using_on_this_expression_appears_unintentional_because_it_always_evaluates_to_the_same_nullishness); } } } - // Returns true if we know that, syntactically, a node will always (or never) - // evaluate to undefined or null - function hasStaticNullishness(node: Node) { + function getSyntacticNullishnessSemantics(node: Node): PredicateSemantics { switch (node.kind) { case SyntaxKind.AwaitExpression: case SyntaxKind.CallExpression: case SyntaxKind.ElementAccessExpression: - case SyntaxKind.Identifier: case SyntaxKind.NewExpression: case SyntaxKind.PropertyAccessExpression: case SyntaxKind.YieldExpression: - return false; + return PredicateSemantics.Sometimes; case SyntaxKind.BinaryExpression: // List of operators that can produce null/undefined: // = ??= ?? || ||= && &&= @@ -39590,10 +39592,24 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { case SyntaxKind.BarBarEqualsToken: case SyntaxKind.AmpersandAmpersandToken: case SyntaxKind.AmpersandAmpersandEqualsToken: - return false; + return PredicateSemantics.Sometimes; + } + return PredicateSemantics.Never; + case SyntaxKind.NullKeyword: + return PredicateSemantics.Always; + case SyntaxKind.TypeAssertionExpression: + case SyntaxKind.AsExpression: + case SyntaxKind.ParenthesizedExpression: + return getSyntacticNullishnessSemantics((node as OuterExpression).expression); + case SyntaxKind.ConditionalExpression: + return getSyntacticNullishnessSemantics((node as ConditionalExpression).whenTrue) | getSyntacticNullishnessSemantics((node as ConditionalExpression).whenFalse); + case SyntaxKind.Identifier: + if ((node as Identifier).escapedText === "undefined") { + return PredicateSemantics.Always; } + return PredicateSemantics.Sometimes; } - return true; + return PredicateSemantics.Never; } // Note that this and `checkBinaryExpression` above should behave mostly the same, except this elides some @@ -39604,7 +39620,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return checkDestructuringAssignment(left, checkExpression(right, checkMode), checkMode, right.kind === SyntaxKind.ThisKeyword); } let leftType: Type; - if (isLogicalOrCoalescingBinaryOperator(operator)) { + if (isBinaryLogicalOperator(operator)) { leftType = checkTruthinessExpression(left, checkMode); } else { @@ -44225,18 +44241,29 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function checkTruthinessOfType(type: Type, node: Node) { - node = skipParentheses(node); - if (type.flags & TypeFlags.Void) { error(node, Diagnostics.An_expression_of_type_void_cannot_be_tested_for_truthiness); + } else { + const semantics = getSyntacticTruthySemantics(node); + if (semantics !== PredicateSemantics.Sometimes) { + error(node, + semantics === PredicateSemantics.Always ? + Diagnostics.This_expression_is_always_truthy_Did_you_mean_to_test_something_else : + Diagnostics.This_expression_is_always_falsy_Did_you_mean_to_test_something_else) + } } - let alwaysTruthy: boolean | undefined; + return type; + } + + function getSyntacticTruthySemantics(node: Node): PredicateSemantics { switch (node.kind) { case SyntaxKind.NumericLiteral: // Allow `while(0)` or `while(1)` - if ((node as NumericLiteral).text === "0" || (node as NumericLiteral).text === "1") break; - // falls through + if ((node as NumericLiteral).text === "0" || (node as NumericLiteral).text === "1") { + return PredicateSemantics.Sometimes; + } + return PredicateSemantics.Always; case SyntaxKind.ArrayLiteralExpression: case SyntaxKind.ArrowFunction: case SyntaxKind.BigIntLiteral: @@ -44246,28 +44273,27 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { case SyntaxKind.JsxSelfClosingElement: case SyntaxKind.ObjectLiteralExpression: case SyntaxKind.RegularExpressionLiteral: - alwaysTruthy = true; - break; + return PredicateSemantics.Always; case SyntaxKind.VoidExpression: - alwaysTruthy = false; - break; + return PredicateSemantics.Never; case SyntaxKind.NoSubstitutionTemplateLiteral: case SyntaxKind.StringLiteral: - alwaysTruthy = !!(node as StringLiteral | NoSubstitutionTemplateLiteral).text; - break; - } - - if (alwaysTruthy !== undefined) { - error( - node, - alwaysTruthy ? - Diagnostics.This_expression_is_always_truthy_Did_you_mean_to_test_something_else : - Diagnostics.This_expression_is_always_falsy_Did_you_mean_to_test_something_else, - ); + return !!(node as StringLiteral | NoSubstitutionTemplateLiteral).text ? PredicateSemantics.Always : PredicateSemantics.Never; + case SyntaxKind.TypeAssertionExpression: + case SyntaxKind.AsExpression: + case SyntaxKind.ParenthesizedExpression: + return getSyntacticTruthySemantics((node as OuterExpression).expression); + case SyntaxKind.ConditionalExpression: + return getSyntacticTruthySemantics((node as ConditionalExpression).whenTrue) | getSyntacticTruthySemantics((node as ConditionalExpression).whenFalse); + case SyntaxKind.Identifier: + if ((node as Identifier).escapedText === "undefined") { + return PredicateSemantics.Never; + } + return PredicateSemantics.Sometimes; } - - return type; + return PredicateSemantics.Sometimes; } + function checkTruthinessExpression(node: Expression, checkMode?: CheckMode) { return checkTruthinessOfType(checkExpression(node, checkMode), node); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 28d69a39e4d74..079c0b8ce9796 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -923,6 +923,14 @@ export const enum RelationComparisonResult { Overflow = ComplexityOverflow | StackDepthOverflow, } +/** @internal */ +export const enum PredicateSemantics { + None = 0, + Always = 1 << 0, + Never = 1 << 1, + Sometimes = Always | Never +} + /** @internal */ export type NodeId = number; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index b29944a5236c3..2bcd1131cd5eb 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -7187,7 +7187,7 @@ export function modifierToFlag(token: SyntaxKind): ModifierFlags { return ModifierFlags.None; } -function isBinaryLogicalOperator(token: SyntaxKind): boolean { +export function isBinaryLogicalOperator(token: SyntaxKind): boolean { return token === SyntaxKind.BarBarToken || token === SyntaxKind.AmpersandAmpersandToken; } diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 3855078b1f285..493c3f0002e85 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -8754,6 +8754,7 @@ declare namespace ts { * ``` */ function getJSDocCommentsAndTags(hostNode: Node): readonly (JSDoc | JSDocTag)[]; + function isBinaryLogicalOperator(token: SyntaxKind): boolean; /** * Create an external source map source file reference */ diff --git a/tests/baselines/reference/conditionalOperatorConditionIsObjectType.errors.txt b/tests/baselines/reference/conditionalOperatorConditionIsObjectType.errors.txt index 092830b257a63..c72262b12182f 100644 --- a/tests/baselines/reference/conditionalOperatorConditionIsObjectType.errors.txt +++ b/tests/baselines/reference/conditionalOperatorConditionIsObjectType.errors.txt @@ -1,17 +1,17 @@ -conditionalOperatorConditionIsObjectType.ts(28,2): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsObjectType.ts(29,2): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsObjectType.ts(30,2): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsObjectType.ts(31,2): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsObjectType.ts(32,2): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsObjectType.ts(33,2): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(28,1): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(29,1): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(30,1): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(31,1): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(32,1): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(33,1): error TS2869: This expression is always truthy. Did you mean to test something else? conditionalOperatorConditionIsObjectType.ts(36,1): error TS1345: An expression of type 'void' cannot be tested for truthiness. conditionalOperatorConditionIsObjectType.ts(39,1): error TS1345: An expression of type 'void' cannot be tested for truthiness. -conditionalOperatorConditionIsObjectType.ts(51,21): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsObjectType.ts(52,25): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsObjectType.ts(53,24): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsObjectType.ts(54,24): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsObjectType.ts(55,24): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsObjectType.ts(56,33): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(51,20): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(52,24): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(53,23): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(54,23): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(55,23): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(56,32): error TS2869: This expression is always truthy. Did you mean to test something else? conditionalOperatorConditionIsObjectType.ts(58,20): error TS1345: An expression of type 'void' cannot be tested for truthiness. conditionalOperatorConditionIsObjectType.ts(61,23): error TS1345: An expression of type 'void' cannot be tested for truthiness. conditionalOperatorConditionIsObjectType.ts(63,32): error TS1345: An expression of type 'void' cannot be tested for truthiness. @@ -46,22 +46,22 @@ conditionalOperatorConditionIsObjectType.ts(63,32): error TS1345: An expression //Cond is an object type literal ((a: string) => a.length) ? exprAny1 : exprAny2; - ~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? ((a: string) => a.length) ? exprBoolean1 : exprBoolean2; - ~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? ({}) ? exprNumber1 : exprNumber2; - ~~ + ~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? ({ a: 1, b: "s" }) ? exprString1 : exprString2; - ~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? ({ a: 1, b: "s" }) ? exprIsObject1 : exprIsObject2; - ~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? ({ a: 1, b: "s" }) ? exprString1: exprBoolean1; // union - ~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? //Cond is an object type expression @@ -85,22 +85,22 @@ conditionalOperatorConditionIsObjectType.ts(63,32): error TS1345: An expression var resultIsStringOrBoolean1 = condObject ? exprString1 : exprBoolean1; // union var resultIsAny2 = ((a: string) => a.length) ? exprAny1 : exprAny2; - ~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? var resultIsBoolean2 = ((a: string) => a.length) ? exprBoolean1 : exprBoolean2; - ~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? var resultIsNumber2 = ({}) ? exprNumber1 : exprNumber2; - ~~ + ~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? var resultIsString2 = ({ a: 1, b: "s" }) ? exprString1 : exprString2; - ~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? var resultIsObject2 = ({ a: 1, b: "s" }) ? exprIsObject1 : exprIsObject2; - ~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? var resultIsStringOrBoolean2 = ({ a: 1, b: "s" }) ? exprString1 : exprBoolean1; // union - ~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? var resultIsAny3 = foo() ? exprAny1 : exprAny2; diff --git a/tests/baselines/reference/conditionalOperatorConditoinIsAnyType.errors.txt b/tests/baselines/reference/conditionalOperatorConditoinIsAnyType.errors.txt index 34e6bd8a183c3..4449dbe66fcff 100644 --- a/tests/baselines/reference/conditionalOperatorConditoinIsAnyType.errors.txt +++ b/tests/baselines/reference/conditionalOperatorConditoinIsAnyType.errors.txt @@ -1,11 +1,15 @@ +conditionalOperatorConditoinIsAnyType.ts(28,1): error TS2870: This expression is always falsy. Did you mean to test something else? conditionalOperatorConditoinIsAnyType.ts(29,1): error TS2869: This expression is always truthy. Did you mean to test something else? conditionalOperatorConditoinIsAnyType.ts(30,1): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditoinIsAnyType.ts(31,1): error TS2870: This expression is always falsy. Did you mean to test something else? +conditionalOperatorConditoinIsAnyType.ts(51,23): error TS2870: This expression is always falsy. Did you mean to test something else? conditionalOperatorConditoinIsAnyType.ts(52,23): error TS2869: This expression is always truthy. Did you mean to test something else? conditionalOperatorConditoinIsAnyType.ts(53,23): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditoinIsAnyType.ts(55,32): error TS2870: This expression is always falsy. Did you mean to test something else? conditionalOperatorConditoinIsAnyType.ts(56,32): error TS2869: This expression is always truthy. Did you mean to test something else? -==== conditionalOperatorConditoinIsAnyType.ts (5 errors) ==== +==== conditionalOperatorConditoinIsAnyType.ts (9 errors) ==== //Cond ? Expr1 : Expr2, Cond is of any type, Expr1 and Expr2 have the same type var condAny: any; var x: any; @@ -34,6 +38,8 @@ conditionalOperatorConditoinIsAnyType.ts(56,32): error TS2869: This expression i null ? exprAny1 : exprAny2; null ? exprBoolean1 : exprBoolean2; undefined ? exprNumber1 : exprNumber2; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? [null, undefined] ? exprString1 : exprString2; ~~~~~~~~~~~~~~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? @@ -41,6 +47,8 @@ conditionalOperatorConditoinIsAnyType.ts(56,32): error TS2869: This expression i ~~~~~~~~~~~~~~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? undefined ? exprString1 : exprBoolean1; // union + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? //Cond is an any type expression x.doSomeThing() ? exprAny1 : exprAny2; @@ -61,6 +69,8 @@ conditionalOperatorConditoinIsAnyType.ts(56,32): error TS2869: This expression i var resultIsAny2 = null ? exprAny1 : exprAny2; var resultIsBoolean2 = null ? exprBoolean1 : exprBoolean2; var resultIsNumber2 = undefined ? exprNumber1 : exprNumber2; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var resultIsString2 = [null, undefined] ? exprString1 : exprString2; ~~~~~~~~~~~~~~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? @@ -69,6 +79,8 @@ conditionalOperatorConditoinIsAnyType.ts(56,32): error TS2869: This expression i !!! error TS2869: This expression is always truthy. Did you mean to test something else? var resultIsStringOrBoolean2 = null ? exprString1 : exprBoolean1; // union var resultIsStringOrBoolean3 = undefined ? exprString1 : exprBoolean1; // union + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var resultIsStringOrBoolean4 = [null, undefined] ? exprString1 : exprBoolean1; // union ~~~~~~~~~~~~~~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? diff --git a/tests/baselines/reference/contextuallyTypeLogicalAnd03.errors.txt b/tests/baselines/reference/contextuallyTypeLogicalAnd03.errors.txt index df7bbfcf26124..31b1e727b878b 100644 --- a/tests/baselines/reference/contextuallyTypeLogicalAnd03.errors.txt +++ b/tests/baselines/reference/contextuallyTypeLogicalAnd03.errors.txt @@ -1,5 +1,5 @@ +contextuallyTypeLogicalAnd03.ts(4,5): error TS2869: This expression is always truthy. Did you mean to test something else? contextuallyTypeLogicalAnd03.ts(4,6): error TS7006: Parameter 'a' implicitly has an 'any' type. -contextuallyTypeLogicalAnd03.ts(4,6): error TS2869: This expression is always truthy. Did you mean to test something else? ==== contextuallyTypeLogicalAnd03.ts (2 errors) ==== @@ -7,7 +7,7 @@ contextuallyTypeLogicalAnd03.ts(4,6): error TS2869: This expression is always tr let y = true; x = (a => a) && (b => b); + ~~~~~~~~ +!!! error TS2869: This expression is always truthy. Did you mean to test something else? ~ -!!! error TS7006: Parameter 'a' implicitly has an 'any' type. - ~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? \ No newline at end of file +!!! error TS7006: Parameter 'a' implicitly has an 'any' type. \ No newline at end of file diff --git a/tests/baselines/reference/declFileTypeAnnotationParenType.errors.txt b/tests/baselines/reference/declFileTypeAnnotationParenType.errors.txt index 81772f25bb03a..8828e7fa0f576 100644 --- a/tests/baselines/reference/declFileTypeAnnotationParenType.errors.txt +++ b/tests/baselines/reference/declFileTypeAnnotationParenType.errors.txt @@ -1,5 +1,5 @@ -declFileTypeAnnotationParenType.ts(8,30): error TS2869: This expression is always truthy. Did you mean to test something else? -declFileTypeAnnotationParenType.ts(9,10): error TS2869: This expression is always truthy. Did you mean to test something else? +declFileTypeAnnotationParenType.ts(8,29): error TS2869: This expression is always truthy. Did you mean to test something else? +declFileTypeAnnotationParenType.ts(9,9): error TS2869: This expression is always truthy. Did you mean to test something else? ==== declFileTypeAnnotationParenType.ts (2 errors) ==== @@ -11,8 +11,8 @@ declFileTypeAnnotationParenType.ts(9,10): error TS2869: This expression is alway var y = [() => new c()]; var k: (() => c) | string = (() => new c()) || ""; - ~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? var l = (() => new c()) || ""; - ~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? \ No newline at end of file diff --git a/tests/baselines/reference/fatarrowfunctionsOptionalArgs.errors.txt b/tests/baselines/reference/fatarrowfunctionsOptionalArgs.errors.txt index 41be1498fa39e..3cb838d4945bc 100644 --- a/tests/baselines/reference/fatarrowfunctionsOptionalArgs.errors.txt +++ b/tests/baselines/reference/fatarrowfunctionsOptionalArgs.errors.txt @@ -1,4 +1,4 @@ -fatarrowfunctionsOptionalArgs.ts(85,2): error TS2869: This expression is always truthy. Did you mean to test something else? +fatarrowfunctionsOptionalArgs.ts(85,1): error TS2869: This expression is always truthy. Did you mean to test something else? fatarrowfunctionsOptionalArgs.ts(88,23): error TS1005: ';' expected. fatarrowfunctionsOptionalArgs.ts(88,38): error TS1005: ';' expected. @@ -89,7 +89,7 @@ fatarrowfunctionsOptionalArgs.ts(88,38): error TS1005: ';' expected. // nested ternary expressions ((a?) => { return a; }) ? (b? ) => { return b; } : (c? ) => { return c; }; - ~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? //multiple levels diff --git a/tests/baselines/reference/generatedContextualTyping.errors.txt b/tests/baselines/reference/generatedContextualTyping.errors.txt index d5188e1c3ee4d..809ebb5c7d0f1 100644 --- a/tests/baselines/reference/generatedContextualTyping.errors.txt +++ b/tests/baselines/reference/generatedContextualTyping.errors.txt @@ -1,3 +1,11 @@ +generatedContextualTyping.ts(219,12): error TS2870: This expression is always falsy. Did you mean to test something else? +generatedContextualTyping.ts(220,12): error TS2870: This expression is always falsy. Did you mean to test something else? +generatedContextualTyping.ts(221,12): error TS2870: This expression is always falsy. Did you mean to test something else? +generatedContextualTyping.ts(222,12): error TS2870: This expression is always falsy. Did you mean to test something else? +generatedContextualTyping.ts(223,12): error TS2870: This expression is always falsy. Did you mean to test something else? +generatedContextualTyping.ts(224,12): error TS2870: This expression is always falsy. Did you mean to test something else? +generatedContextualTyping.ts(225,12): error TS2870: This expression is always falsy. Did you mean to test something else? +generatedContextualTyping.ts(226,12): error TS2870: This expression is always falsy. Did you mean to test something else? generatedContextualTyping.ts(259,26): error TS2869: This expression is always truthy. Did you mean to test something else? generatedContextualTyping.ts(260,35): error TS2869: This expression is always truthy. Did you mean to test something else? generatedContextualTyping.ts(261,29): error TS2869: This expression is always truthy. Did you mean to test something else? @@ -6,6 +14,14 @@ generatedContextualTyping.ts(263,20): error TS2869: This expression is always tr generatedContextualTyping.ts(264,25): error TS2869: This expression is always truthy. Did you mean to test something else? generatedContextualTyping.ts(265,36): error TS2869: This expression is always truthy. Did you mean to test something else? generatedContextualTyping.ts(266,28): error TS2869: This expression is always truthy. Did you mean to test something else? +generatedContextualTyping.ts(267,26): error TS2870: This expression is always falsy. Did you mean to test something else? +generatedContextualTyping.ts(268,26): error TS2870: This expression is always falsy. Did you mean to test something else? +generatedContextualTyping.ts(269,29): error TS2870: This expression is always falsy. Did you mean to test something else? +generatedContextualTyping.ts(270,29): error TS2870: This expression is always falsy. Did you mean to test something else? +generatedContextualTyping.ts(271,20): error TS2870: This expression is always falsy. Did you mean to test something else? +generatedContextualTyping.ts(272,25): error TS2870: This expression is always falsy. Did you mean to test something else? +generatedContextualTyping.ts(273,36): error TS2870: This expression is always falsy. Did you mean to test something else? +generatedContextualTyping.ts(274,28): error TS2870: This expression is always falsy. Did you mean to test something else? generatedContextualTyping.ts(275,26): error TS2869: This expression is always truthy. Did you mean to test something else? generatedContextualTyping.ts(276,35): error TS2869: This expression is always truthy. Did you mean to test something else? generatedContextualTyping.ts(277,29): error TS2869: This expression is always truthy. Did you mean to test something else? @@ -16,7 +32,7 @@ generatedContextualTyping.ts(281,36): error TS2869: This expression is always tr generatedContextualTyping.ts(282,28): error TS2869: This expression is always truthy. Did you mean to test something else? -==== generatedContextualTyping.ts (16 errors) ==== +==== generatedContextualTyping.ts (32 errors) ==== class Base { private p; } class Derived1 extends Base { private m; } class Derived2 extends Base { private n; } @@ -236,13 +252,29 @@ generatedContextualTyping.ts(282,28): error TS2869: This expression is always tr var x214 = <{n: Base[]; } >{ n: [d1, d2] }; var x216 = >{ func: n => { return [d1, d2]; } }; var x217 = (<() => Base[]>undefined) || function() { return [d1, d2] }; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var x218 = (<() => Base[]>undefined) || function named() { return [d1, d2] }; + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var x219 = (<{ (): Base[]; }>undefined) || function() { return [d1, d2] }; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var x220 = (<{ (): Base[]; }>undefined) || function named() { return [d1, d2] }; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var x221 = (undefined) || [d1, d2]; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var x222 = (>undefined) || [d1, d2]; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var x223 = (<{ [n: number]: Base; }>undefined) || [d1, d2]; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var x224 = (<{n: Base[]; } >undefined) || { n: [d1, d2] }; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var x225: () => Base[]; x225 = () => [d1, d2]; var x226: () => Base[]; x226 = function() { return [d1, d2] }; var x227: () => Base[]; x227 = function named() { return [d1, d2] }; @@ -300,13 +332,29 @@ generatedContextualTyping.ts(282,28): error TS2869: This expression is always tr ~~~~~~~~~~~~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? var x269: () => Base[] = undefined || function() { return [d1, d2] }; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var x270: () => Base[] = undefined || function named() { return [d1, d2] }; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var x271: { (): Base[]; } = undefined || function() { return [d1, d2] }; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var x272: { (): Base[]; } = undefined || function named() { return [d1, d2] }; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var x273: Base[] = undefined || [d1, d2]; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var x274: Array = undefined || [d1, d2]; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var x275: { [n: number]: Base; } = undefined || [d1, d2]; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var x276: {n: Base[]; } = undefined || { n: [d1, d2] }; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var x277: () => Base[] = function() { return [d1, d2] } || function() { return [d1, d2] }; ~~~~~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? diff --git a/tests/baselines/reference/ifDoWhileStatements.errors.txt b/tests/baselines/reference/ifDoWhileStatements.errors.txt index 8738d7709117f..d0f9d226df311 100644 --- a/tests/baselines/reference/ifDoWhileStatements.errors.txt +++ b/tests/baselines/reference/ifDoWhileStatements.errors.txt @@ -1,3 +1,6 @@ +ifDoWhileStatements.ts(48,5): error TS2870: This expression is always falsy. Did you mean to test something else? +ifDoWhileStatements.ts(49,8): error TS2870: This expression is always falsy. Did you mean to test something else? +ifDoWhileStatements.ts(50,13): error TS2870: This expression is always falsy. Did you mean to test something else? ifDoWhileStatements.ts(56,5): error TS2869: This expression is always truthy. Did you mean to test something else? ifDoWhileStatements.ts(57,8): error TS2869: This expression is always truthy. Did you mean to test something else? ifDoWhileStatements.ts(58,13): error TS2869: This expression is always truthy. Did you mean to test something else? @@ -24,7 +27,7 @@ ifDoWhileStatements.ts(85,8): error TS2869: This expression is always truthy. Di ifDoWhileStatements.ts(86,13): error TS2869: This expression is always truthy. Did you mean to test something else? -==== ifDoWhileStatements.ts (24 errors) ==== +==== ifDoWhileStatements.ts (27 errors) ==== interface I { id: number; } @@ -73,8 +76,14 @@ ifDoWhileStatements.ts(86,13): error TS2869: This expression is always truthy. D do { }while(null) if (undefined) { } + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? while (undefined) { } + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? do { }while(undefined) + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? if (0.0) { } while (0.0) { } diff --git a/tests/baselines/reference/initializersWidened.errors.txt b/tests/baselines/reference/initializersWidened.errors.txt index 3ad7491f03ba9..c076ca15b57a8 100644 --- a/tests/baselines/reference/initializersWidened.errors.txt +++ b/tests/baselines/reference/initializersWidened.errors.txt @@ -1,8 +1,10 @@ +initializersWidened.ts(19,10): error TS2870: This expression is always falsy. Did you mean to test something else? initializersWidened.ts(20,10): error TS2870: This expression is always falsy. Did you mean to test something else? +initializersWidened.ts(23,10): error TS2870: This expression is always falsy. Did you mean to test something else? initializersWidened.ts(24,10): error TS2870: This expression is always falsy. Did you mean to test something else? -==== initializersWidened.ts (2 errors) ==== +==== initializersWidened.ts (4 errors) ==== // these are widened to any at the point of assignment var x1 = null; @@ -22,12 +24,16 @@ initializersWidened.ts(24,10): error TS2870: This expression is always falsy. Di var x4 = null || null; var y4 = undefined || undefined; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var z4 = void 0 || void 0; ~~~~~~ !!! error TS2870: This expression is always falsy. Did you mean to test something else? var x5 = null || x2; var y5 = undefined || y2; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var z5 = void 0 || y2; ~~~~~~ !!! error TS2870: This expression is always falsy. Did you mean to test something else? \ No newline at end of file diff --git a/tests/baselines/reference/logicalAndOperatorWithEveryType.errors.txt b/tests/baselines/reference/logicalAndOperatorWithEveryType.errors.txt index 224879a8bec8f..24834f4d9f40b 100644 --- a/tests/baselines/reference/logicalAndOperatorWithEveryType.errors.txt +++ b/tests/baselines/reference/logicalAndOperatorWithEveryType.errors.txt @@ -1,16 +1,26 @@ logicalAndOperatorWithEveryType.ts(19,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalAndOperatorWithEveryType.ts(24,12): error TS2870: This expression is always falsy. Did you mean to test something else? logicalAndOperatorWithEveryType.ts(30,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalAndOperatorWithEveryType.ts(35,12): error TS2870: This expression is always falsy. Did you mean to test something else? logicalAndOperatorWithEveryType.ts(41,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalAndOperatorWithEveryType.ts(46,12): error TS2870: This expression is always falsy. Did you mean to test something else? logicalAndOperatorWithEveryType.ts(52,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalAndOperatorWithEveryType.ts(57,12): error TS2870: This expression is always falsy. Did you mean to test something else? logicalAndOperatorWithEveryType.ts(63,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalAndOperatorWithEveryType.ts(68,12): error TS2870: This expression is always falsy. Did you mean to test something else? logicalAndOperatorWithEveryType.ts(74,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalAndOperatorWithEveryType.ts(79,12): error TS2870: This expression is always falsy. Did you mean to test something else? logicalAndOperatorWithEveryType.ts(85,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalAndOperatorWithEveryType.ts(90,12): error TS2870: This expression is always falsy. Did you mean to test something else? logicalAndOperatorWithEveryType.ts(96,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalAndOperatorWithEveryType.ts(101,12): error TS2870: This expression is always falsy. Did you mean to test something else? logicalAndOperatorWithEveryType.ts(107,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalAndOperatorWithEveryType.ts(112,12): error TS2870: This expression is always falsy. Did you mean to test something else? logicalAndOperatorWithEveryType.ts(118,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalAndOperatorWithEveryType.ts(123,12): error TS2870: This expression is always falsy. Did you mean to test something else? -==== logicalAndOperatorWithEveryType.ts (10 errors) ==== +==== logicalAndOperatorWithEveryType.ts (20 errors) ==== // The && operator permits the operands to be of any type and produces a result of the same // type as the second operand. @@ -37,6 +47,8 @@ logicalAndOperatorWithEveryType.ts(118,11): error TS1345: An expression of type var ra8 = a8 && a1; var ra9 = null && a1; var ra10 = undefined && a1; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var rb1 = a1 && a2; var rb2 = a2 && a2; @@ -50,6 +62,8 @@ logicalAndOperatorWithEveryType.ts(118,11): error TS1345: An expression of type var rb8 = a8 && a2; var rb9 = null && a2; var rb10 = undefined && a2; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var rc1 = a1 && a3; var rc2 = a2 && a3; @@ -63,6 +77,8 @@ logicalAndOperatorWithEveryType.ts(118,11): error TS1345: An expression of type var rc8 = a8 && a3; var rc9 = null && a3; var rc10 = undefined && a3; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var rd1 = a1 && a4; var rd2 = a2 && a4; @@ -76,6 +92,8 @@ logicalAndOperatorWithEveryType.ts(118,11): error TS1345: An expression of type var rd8 = a8 && a4; var rd9 = null && a4; var rd10 = undefined && a4; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var re1 = a1 && a5; var re2 = a2 && a5; @@ -89,6 +107,8 @@ logicalAndOperatorWithEveryType.ts(118,11): error TS1345: An expression of type var re8 = a8 && a5; var re9 = null && a5; var re10 = undefined && a5; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var rf1 = a1 && a6; var rf2 = a2 && a6; @@ -102,6 +122,8 @@ logicalAndOperatorWithEveryType.ts(118,11): error TS1345: An expression of type var rf8 = a8 && a6; var rf9 = null && a6; var rf10 = undefined && a6; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var rg1 = a1 && a7; var rg2 = a2 && a7; @@ -115,6 +137,8 @@ logicalAndOperatorWithEveryType.ts(118,11): error TS1345: An expression of type var rg8 = a8 && a7; var rg9 = null && a7; var rg10 = undefined && a7; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var rh1 = a1 && a8; var rh2 = a2 && a8; @@ -128,6 +152,8 @@ logicalAndOperatorWithEveryType.ts(118,11): error TS1345: An expression of type var rh8 = a8 && a8; var rh9 = null && a8; var rh10 = undefined && a8; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var ri1 = a1 && null; var ri2 = a2 && null; @@ -141,6 +167,8 @@ logicalAndOperatorWithEveryType.ts(118,11): error TS1345: An expression of type var ri8 = a8 && null; var ri9 = null && null; var ri10 = undefined && null; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var rj1 = a1 && undefined; var rj2 = a2 && undefined; @@ -153,4 +181,6 @@ logicalAndOperatorWithEveryType.ts(118,11): error TS1345: An expression of type var rj7 = a7 && undefined; var rj8 = a8 && undefined; var rj9 = null && undefined; - var rj10 = undefined && undefined; \ No newline at end of file + var rj10 = undefined && undefined; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? \ No newline at end of file diff --git a/tests/baselines/reference/logicalNotOperatorWithAnyOtherType.errors.txt b/tests/baselines/reference/logicalNotOperatorWithAnyOtherType.errors.txt index be84088895d18..49503ec38dfcd 100644 --- a/tests/baselines/reference/logicalNotOperatorWithAnyOtherType.errors.txt +++ b/tests/baselines/reference/logicalNotOperatorWithAnyOtherType.errors.txt @@ -1,10 +1,11 @@ +logicalNotOperatorWithAnyOtherType.ts(33,25): error TS2870: This expression is always falsy. Did you mean to test something else? logicalNotOperatorWithAnyOtherType.ts(45,27): error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. logicalNotOperatorWithAnyOtherType.ts(46,27): error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. logicalNotOperatorWithAnyOtherType.ts(47,27): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. logicalNotOperatorWithAnyOtherType.ts(57,1): error TS2695: Left side of comma operator is unused and has no side effects. -==== logicalNotOperatorWithAnyOtherType.ts (4 errors) ==== +==== logicalNotOperatorWithAnyOtherType.ts (5 errors) ==== // ! operator on any type var ANY: any; @@ -38,6 +39,8 @@ logicalNotOperatorWithAnyOtherType.ts(57,1): error TS2695: Left side of comma op // any type literal var ResultIsBoolean7 = !undefined; + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var ResultIsBoolean8 = !null; // any type expressions diff --git a/tests/baselines/reference/logicalOrOperatorWithEveryType.errors.txt b/tests/baselines/reference/logicalOrOperatorWithEveryType.errors.txt index f15ec315745c4..0c2a0e96ea09b 100644 --- a/tests/baselines/reference/logicalOrOperatorWithEveryType.errors.txt +++ b/tests/baselines/reference/logicalOrOperatorWithEveryType.errors.txt @@ -1,16 +1,26 @@ logicalOrOperatorWithEveryType.ts(21,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalOrOperatorWithEveryType.ts(26,12): error TS2870: This expression is always falsy. Did you mean to test something else? logicalOrOperatorWithEveryType.ts(32,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalOrOperatorWithEveryType.ts(37,11): error TS2870: This expression is always falsy. Did you mean to test something else? logicalOrOperatorWithEveryType.ts(43,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalOrOperatorWithEveryType.ts(48,12): error TS2870: This expression is always falsy. Did you mean to test something else? logicalOrOperatorWithEveryType.ts(54,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalOrOperatorWithEveryType.ts(59,12): error TS2870: This expression is always falsy. Did you mean to test something else? logicalOrOperatorWithEveryType.ts(65,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalOrOperatorWithEveryType.ts(70,12): error TS2870: This expression is always falsy. Did you mean to test something else? logicalOrOperatorWithEveryType.ts(76,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalOrOperatorWithEveryType.ts(81,12): error TS2870: This expression is always falsy. Did you mean to test something else? logicalOrOperatorWithEveryType.ts(87,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalOrOperatorWithEveryType.ts(92,12): error TS2870: This expression is always falsy. Did you mean to test something else? logicalOrOperatorWithEveryType.ts(98,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalOrOperatorWithEveryType.ts(103,12): error TS2870: This expression is always falsy. Did you mean to test something else? logicalOrOperatorWithEveryType.ts(109,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalOrOperatorWithEveryType.ts(114,12): error TS2870: This expression is always falsy. Did you mean to test something else? logicalOrOperatorWithEveryType.ts(120,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalOrOperatorWithEveryType.ts(125,12): error TS2870: This expression is always falsy. Did you mean to test something else? -==== logicalOrOperatorWithEveryType.ts (10 errors) ==== +==== logicalOrOperatorWithEveryType.ts (20 errors) ==== // The || operator permits the operands to be of any type. // If the || expression is not contextually typed, the right operand is contextually typed // by the type of the left operand and the result is of the best common type of the two @@ -39,6 +49,8 @@ logicalOrOperatorWithEveryType.ts(120,11): error TS1345: An expression of type ' var ra8 = a8 || a1; // array || any is any var ra9 = null || a1; // null || any is any var ra10 = undefined || a1; // undefined || any is any + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var rb1 = a1 || a2; // any || boolean is any var rb2 = a2 || a2; // boolean || boolean is boolean @@ -52,6 +64,8 @@ logicalOrOperatorWithEveryType.ts(120,11): error TS1345: An expression of type ' var rb8 = a8 || a2; // array || boolean is array | boolean var rb9 = null || a2; // null || boolean is boolean var rb10= undefined || a2; // undefined || boolean is boolean + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var rc1 = a1 || a3; // any || number is any var rc2 = a2 || a3; // boolean || number is boolean | number @@ -65,6 +79,8 @@ logicalOrOperatorWithEveryType.ts(120,11): error TS1345: An expression of type ' var rc8 = a8 || a3; // array || number is array | number var rc9 = null || a3; // null || number is number var rc10 = undefined || a3; // undefined || number is number + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var rd1 = a1 || a4; // any || string is any var rd2 = a2 || a4; // boolean || string is boolean | string @@ -78,6 +94,8 @@ logicalOrOperatorWithEveryType.ts(120,11): error TS1345: An expression of type ' var rd8 = a8 || a4; // array || string is array | string var rd9 = null || a4; // null || string is string var rd10 = undefined || a4; // undefined || string is string + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var re1 = a1 || a5; // any || void is any var re2 = a2 || a5; // boolean || void is boolean | void @@ -91,6 +109,8 @@ logicalOrOperatorWithEveryType.ts(120,11): error TS1345: An expression of type ' var re8 = a8 || a5; // array || void is array | void var re9 = null || a5; // null || void is void var re10 = undefined || a5; // undefined || void is void + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var rg1 = a1 || a6; // any || enum is any var rg2 = a2 || a6; // boolean || enum is boolean | enum @@ -104,6 +124,8 @@ logicalOrOperatorWithEveryType.ts(120,11): error TS1345: An expression of type ' var rg8 = a8 || a6; // array || enum is array | enum var rg9 = null || a6; // null || enum is E var rg10 = undefined || a6; // undefined || enum is E + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var rh1 = a1 || a7; // any || object is any var rh2 = a2 || a7; // boolean || object is boolean | object @@ -117,6 +139,8 @@ logicalOrOperatorWithEveryType.ts(120,11): error TS1345: An expression of type ' var rh8 = a8 || a7; // array || object is array | object var rh9 = null || a7; // null || object is object var rh10 = undefined || a7; // undefined || object is object + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var ri1 = a1 || a8; // any || array is any var ri2 = a2 || a8; // boolean || array is boolean | array @@ -130,6 +154,8 @@ logicalOrOperatorWithEveryType.ts(120,11): error TS1345: An expression of type ' var ri8 = a8 || a8; // array || array is array var ri9 = null || a8; // null || array is array var ri10 = undefined || a8; // undefined || array is array + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var rj1 = a1 || null; // any || null is any var rj2 = a2 || null; // boolean || null is boolean @@ -143,6 +169,8 @@ logicalOrOperatorWithEveryType.ts(120,11): error TS1345: An expression of type ' var rj8 = a8 || null; // array || null is array var rj9 = null || null; // null || null is any var rj10 = undefined || null; // undefined || null is any + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? var rf1 = a1 || undefined; // any || undefined is any var rf2 = a2 || undefined; // boolean || undefined is boolean @@ -155,4 +183,6 @@ logicalOrOperatorWithEveryType.ts(120,11): error TS1345: An expression of type ' var rf7 = a7 || undefined; // object || undefined is object var rf8 = a8 || undefined; // array || undefined is array var rf9 = null || undefined; // null || undefined is any - var rf10 = undefined || undefined; // undefined || undefined is any \ No newline at end of file + var rf10 = undefined || undefined; // undefined || undefined is any + ~~~~~~~~~ +!!! error TS2870: This expression is always falsy. Did you mean to test something else? \ No newline at end of file diff --git a/tests/baselines/reference/parserArrowFunctionExpression3.errors.txt b/tests/baselines/reference/parserArrowFunctionExpression3.errors.txt index 0cd338eef3e50..400ae09f18799 100644 --- a/tests/baselines/reference/parserArrowFunctionExpression3.errors.txt +++ b/tests/baselines/reference/parserArrowFunctionExpression3.errors.txt @@ -1,5 +1,5 @@ parserArrowFunctionExpression3.ts(1,1): error TS2304: Cannot find name 'a'. -parserArrowFunctionExpression3.ts(1,6): error TS2869: This expression is always truthy. Did you mean to test something else? +parserArrowFunctionExpression3.ts(1,5): error TS2869: This expression is always truthy. Did you mean to test something else? parserArrowFunctionExpression3.ts(1,16): error TS1005: ')' expected. parserArrowFunctionExpression3.ts(1,19): error TS2304: Cannot find name 'a'. parserArrowFunctionExpression3.ts(1,20): error TS1005: ';' expected. @@ -9,7 +9,7 @@ parserArrowFunctionExpression3.ts(1,20): error TS1005: ';' expected. a = (() => { } || a) ~ !!! error TS2304: Cannot find name 'a'. - ~~~~~~~~~ + ~~~~~~~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? ~~ !!! error TS1005: ')' expected. diff --git a/tests/baselines/reference/predicateSemantics.errors.txt b/tests/baselines/reference/predicateSemantics.errors.txt new file mode 100644 index 0000000000000..22ae815b5e613 --- /dev/null +++ b/tests/baselines/reference/predicateSemantics.errors.txt @@ -0,0 +1,29 @@ +predicateSemantics.ts(7,16): error TS2871: Using ?? on this expression appears unintentional because it always evaluates to the same nullishness. +predicateSemantics.ts(10,16): error TS2871: Using ?? on this expression appears unintentional because it always evaluates to the same nullishness. + + +==== predicateSemantics.ts (2 errors) ==== + declare let cond: any; + + // OK: One or other operand is possibly nullish + const test1 = (cond ? undefined : 32) ?? "possibly reached"; + + // Not OK: Both operands nullish + const test2 = (cond ? undefined : null) ?? "always reached"; + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2871: Using ?? on this expression appears unintentional because it always evaluates to the same nullishness. + + // Not OK: Both operands non-nullish + const test3 = (cond ? 132 : 17) ?? "unreachable"; + ~~~~~~~~~~~~~~~ +!!! error TS2871: Using ?? on this expression appears unintentional because it always evaluates to the same nullishness. + + // Parens + const test4 = (cond ? (undefined) : (17)) ?? 42; + + // Should be OK (special case) + if (!!true) { + + } + + \ No newline at end of file diff --git a/tests/baselines/reference/predicateSemantics.js b/tests/baselines/reference/predicateSemantics.js new file mode 100644 index 0000000000000..24f8f0a716640 --- /dev/null +++ b/tests/baselines/reference/predicateSemantics.js @@ -0,0 +1,37 @@ +//// [tests/cases/compiler/predicateSemantics.ts] //// + +//// [predicateSemantics.ts] +declare let cond: any; + +// OK: One or other operand is possibly nullish +const test1 = (cond ? undefined : 32) ?? "possibly reached"; + +// Not OK: Both operands nullish +const test2 = (cond ? undefined : null) ?? "always reached"; + +// Not OK: Both operands non-nullish +const test3 = (cond ? 132 : 17) ?? "unreachable"; + +// Parens +const test4 = (cond ? (undefined) : (17)) ?? 42; + +// Should be OK (special case) +if (!!true) { + +} + + + +//// [predicateSemantics.js] +var _a, _b, _c, _d; +// OK: One or other operand is possibly nullish +var test1 = (_a = (cond ? undefined : 32)) !== null && _a !== void 0 ? _a : "possibly reached"; +// Not OK: Both operands nullish +var test2 = (_b = (cond ? undefined : null)) !== null && _b !== void 0 ? _b : "always reached"; +// Not OK: Both operands non-nullish +var test3 = (_c = (cond ? 132 : 17)) !== null && _c !== void 0 ? _c : "unreachable"; +// Parens +var test4 = (_d = (cond ? (undefined) : (17))) !== null && _d !== void 0 ? _d : 42; +// Should be OK (special case) +if (!!true) { +} diff --git a/tests/baselines/reference/predicateSemantics.symbols b/tests/baselines/reference/predicateSemantics.symbols new file mode 100644 index 0000000000000..a20a75a9cea81 --- /dev/null +++ b/tests/baselines/reference/predicateSemantics.symbols @@ -0,0 +1,35 @@ +//// [tests/cases/compiler/predicateSemantics.ts] //// + +=== predicateSemantics.ts === +declare let cond: any; +>cond : Symbol(cond, Decl(predicateSemantics.ts, 0, 11)) + +// OK: One or other operand is possibly nullish +const test1 = (cond ? undefined : 32) ?? "possibly reached"; +>test1 : Symbol(test1, Decl(predicateSemantics.ts, 3, 5)) +>cond : Symbol(cond, Decl(predicateSemantics.ts, 0, 11)) +>undefined : Symbol(undefined) + +// Not OK: Both operands nullish +const test2 = (cond ? undefined : null) ?? "always reached"; +>test2 : Symbol(test2, Decl(predicateSemantics.ts, 6, 5)) +>cond : Symbol(cond, Decl(predicateSemantics.ts, 0, 11)) +>undefined : Symbol(undefined) + +// Not OK: Both operands non-nullish +const test3 = (cond ? 132 : 17) ?? "unreachable"; +>test3 : Symbol(test3, Decl(predicateSemantics.ts, 9, 5)) +>cond : Symbol(cond, Decl(predicateSemantics.ts, 0, 11)) + +// Parens +const test4 = (cond ? (undefined) : (17)) ?? 42; +>test4 : Symbol(test4, Decl(predicateSemantics.ts, 12, 5)) +>cond : Symbol(cond, Decl(predicateSemantics.ts, 0, 11)) +>undefined : Symbol(undefined) + +// Should be OK (special case) +if (!!true) { + +} + + diff --git a/tests/baselines/reference/predicateSemantics.types b/tests/baselines/reference/predicateSemantics.types new file mode 100644 index 0000000000000..7890cb5cd346d --- /dev/null +++ b/tests/baselines/reference/predicateSemantics.types @@ -0,0 +1,97 @@ +//// [tests/cases/compiler/predicateSemantics.ts] //// + +=== predicateSemantics.ts === +declare let cond: any; +>cond : any +> : ^^^ + +// OK: One or other operand is possibly nullish +const test1 = (cond ? undefined : 32) ?? "possibly reached"; +>test1 : 32 | "possibly reached" +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>(cond ? undefined : 32) ?? "possibly reached" : 32 | "possibly reached" +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>(cond ? undefined : 32) : 32 +> : ^^ +>cond ? undefined : 32 : 32 +> : ^^ +>cond : any +> : ^^^ +>undefined : undefined +> : ^^^^^^^^^ +>32 : 32 +> : ^^ +>"possibly reached" : "possibly reached" +> : ^^^^^^^^^^^^^^^^^^ + +// Not OK: Both operands nullish +const test2 = (cond ? undefined : null) ?? "always reached"; +>test2 : "always reached" +> : ^^^^^^^^^^^^^^^^ +>(cond ? undefined : null) ?? "always reached" : "always reached" +> : ^^^^^^^^^^^^^^^^ +>(cond ? undefined : null) : null +> : ^^^^ +>cond ? undefined : null : null +> : ^^^^ +>cond : any +> : ^^^ +>undefined : undefined +> : ^^^^^^^^^ +>"always reached" : "always reached" +> : ^^^^^^^^^^^^^^^^ + +// Not OK: Both operands non-nullish +const test3 = (cond ? 132 : 17) ?? "unreachable"; +>test3 : 132 | 17 | "unreachable" +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>(cond ? 132 : 17) ?? "unreachable" : 132 | 17 | "unreachable" +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>(cond ? 132 : 17) : 132 | 17 +> : ^^^^^^^^ +>cond ? 132 : 17 : 132 | 17 +> : ^^^^^^^^ +>cond : any +> : ^^^ +>132 : 132 +> : ^^^ +>17 : 17 +> : ^^ +>"unreachable" : "unreachable" +> : ^^^^^^^^^^^^^ + +// Parens +const test4 = (cond ? (undefined) : (17)) ?? 42; +>test4 : 17 | 42 +> : ^^^^^^^ +>(cond ? (undefined) : (17)) ?? 42 : 17 | 42 +> : ^^^^^^^ +>(cond ? (undefined) : (17)) : 17 +> : ^^ +>cond ? (undefined) : (17) : 17 +> : ^^ +>cond : any +> : ^^^ +>(undefined) : undefined +> : ^^^^^^^^^ +>undefined : undefined +> : ^^^^^^^^^ +>(17) : 17 +> : ^^ +>17 : 17 +> : ^^ +>42 : 42 +> : ^^ + +// Should be OK (special case) +if (!!true) { +>!!true : boolean +> : ^^^^^^^ +>!true : boolean +> : ^^^^^^^ +>true : true +> : ^^^^ + +} + + diff --git a/tests/baselines/reference/symbolType11.errors.txt b/tests/baselines/reference/symbolType11.errors.txt index e3ee4da22f187..9b714271835e4 100644 --- a/tests/baselines/reference/symbolType11.errors.txt +++ b/tests/baselines/reference/symbolType11.errors.txt @@ -1,4 +1,4 @@ -symbolType11.ts(7,2): error TS2869: This expression is always truthy. Did you mean to test something else? +symbolType11.ts(7,1): error TS2869: This expression is always truthy. Did you mean to test something else? ==== symbolType11.ts (1 errors) ==== @@ -9,5 +9,5 @@ symbolType11.ts(7,2): error TS2869: This expression is always truthy. Did you me s || s; s || 1; ({}) || s; - ~~ + ~~~~ !!! error TS2869: This expression is always truthy. Did you mean to test something else? \ No newline at end of file diff --git a/tests/cases/compiler/predicateSemantics.ts b/tests/cases/compiler/predicateSemantics.ts new file mode 100644 index 0000000000000..b8999c32afecc --- /dev/null +++ b/tests/cases/compiler/predicateSemantics.ts @@ -0,0 +1,19 @@ +declare let cond: any; + +// OK: One or other operand is possibly nullish +const test1 = (cond ? undefined : 32) ?? "possibly reached"; + +// Not OK: Both operands nullish +const test2 = (cond ? undefined : null) ?? "always reached"; + +// Not OK: Both operands non-nullish +const test3 = (cond ? 132 : 17) ?? "unreachable"; + +// Parens +const test4 = (cond ? (undefined) : (17)) ?? 42; + +// Should be OK (special case) +if (!!true) { + +} + From f4a42518f6d2fcf3894d3cda1ca03df95512ddd0 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 10 Jul 2024 10:29:57 -0700 Subject: [PATCH 04/12] Format --- src/compiler/checker.ts | 17 ++++++++++------- src/compiler/types.ts | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 64bb60ecedf10..492a59bccccb2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -470,6 +470,7 @@ import { isAutoAccessorPropertyDeclaration, isAwaitExpression, isBinaryExpression, + isBinaryLogicalOperator, isBindableObjectDefinePropertyCall, isBindableStaticElementAccessExpression, isBindableStaticNameExpression, @@ -914,6 +915,7 @@ import { OptionalTypeNode, or, orderedRemoveItemAt, + OuterExpression, OuterExpressionKinds, ParameterDeclaration, parameterIsThisKeyword, @@ -929,6 +931,7 @@ import { PatternAmbientModule, PlusToken, PostfixUnaryExpression, + PredicateSemantics, PrefixUnaryExpression, PrivateIdentifier, Program, @@ -1115,9 +1118,6 @@ import { WideningContext, WithStatement, YieldExpression, - PredicateSemantics, - OuterExpression, - isBinaryLogicalOperator, } from "./_namespaces/ts.js"; import * as moduleSpecifiers from "./_namespaces/ts.moduleSpecifiers.js"; import * as performance from "./_namespaces/ts.performance.js"; @@ -44243,13 +44243,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function checkTruthinessOfType(type: Type, node: Node) { if (type.flags & TypeFlags.Void) { error(node, Diagnostics.An_expression_of_type_void_cannot_be_tested_for_truthiness); - } else { + } + else { const semantics = getSyntacticTruthySemantics(node); if (semantics !== PredicateSemantics.Sometimes) { - error(node, + error( + node, semantics === PredicateSemantics.Always ? - Diagnostics.This_expression_is_always_truthy_Did_you_mean_to_test_something_else : - Diagnostics.This_expression_is_always_falsy_Did_you_mean_to_test_something_else) + Diagnostics.This_expression_is_always_truthy_Did_you_mean_to_test_something_else : + Diagnostics.This_expression_is_always_falsy_Did_you_mean_to_test_something_else, + ); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 079c0b8ce9796..78e916c2af097 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -928,7 +928,7 @@ export const enum PredicateSemantics { None = 0, Always = 1 << 0, Never = 1 << 1, - Sometimes = Always | Never + Sometimes = Always | Never, } /** @internal */ From ca1034fa6e994ca02b89e414ea4196fe9f1b6f73 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Fri, 19 Jul 2024 16:05:10 -0700 Subject: [PATCH 05/12] Update error messages --- src/compiler/checker.ts | 19 ++- src/compiler/diagnosticMessages.json | 15 +- .../reference/checkJsdocReturnTag1.errors.txt | 4 +- .../reference/checkJsdocReturnTag2.errors.txt | 4 +- .../computedPropertyNames46_ES5.errors.txt | 4 +- .../computedPropertyNames46_ES6.errors.txt | 4 +- .../computedPropertyNames48_ES5.errors.txt | 4 +- .../computedPropertyNames48_ES6.errors.txt | 4 +- ...alOperatorConditionIsNumberType.errors.txt | 24 ++-- ...alOperatorConditionIsObjectType.errors.txt | 48 +++---- ...ionalOperatorConditoinIsAnyType.errors.txt | 36 ++--- ...alOperatorConditoinIsStringType.errors.txt | 48 +++---- .../baselines/reference/constEnum4.errors.txt | 4 +- .../contextuallyTypeLogicalAnd03.errors.txt | 4 +- .../contextuallyTypingOrOperator.errors.txt | 4 +- .../contextuallyTypingOrOperator2.errors.txt | 4 +- .../controlFlowForStatement.errors.txt | 8 +- ...declFileTypeAnnotationParenType.errors.txt | 8 +- ...clarationEmitInferredTypeAlias1.errors.txt | 4 +- ...clarationEmitInferredTypeAlias2.errors.txt | 4 +- ...clarationEmitInferredTypeAlias3.errors.txt | 4 +- ...clarationEmitInferredTypeAlias5.errors.txt | 4 +- ...clarationEmitInferredTypeAlias6.errors.txt | 4 +- ...clarationEmitInferredTypeAlias7.errors.txt | 4 +- ...structuringParameterProperties1.errors.txt | 4 +- ...onentiationOperatorSyntaxError2.errors.txt | 8 +- ...idSimpleUnaryExpressionOperands.errors.txt | 8 +- .../fatarrowfunctionsOptionalArgs.errors.txt | 4 +- .../reference/for-inStatements.errors.txt | 12 +- .../for-inStatementsInvalid.errors.txt | 12 +- .../generatedContextualTyping.errors.txt | 128 +++++++++--------- .../reference/ifDoWhileStatements.errors.txt | 108 +++++++-------- .../reference/initializersWidened.errors.txt | 16 +-- ...logicalAndOperatorWithEveryType.errors.txt | 40 +++--- ...icalNotOperatorWithAnyOtherType.errors.txt | 4 +- ...gicalNotOperatorWithBooleanType.errors.txt | 4 +- ...ogicalNotOperatorWithNumberType.errors.txt | 8 +- ...ogicalNotOperatorWithStringType.errors.txt | 16 +-- ...OrExpressionIsContextuallyTyped.errors.txt | 4 +- .../logicalOrOperatorWithEveryType.errors.txt | 40 +++--- .../reference/nestedIfStatement.errors.txt | 8 +- .../reference/noImplicitAnyForIn.errors.txt | 4 +- .../nullishCoalescingOperator1.errors.txt | 4 +- .../nullishCoalescingOperator7.errors.txt | 12 +- .../parserArrowFunctionExpression3.errors.txt | 4 +- .../parserRegularExpression3.errors.txt | 4 +- .../reference/predicateSemantics.errors.txt | 36 ++++- .../baselines/reference/predicateSemantics.js | 31 ++++- .../reference/predicateSemantics.symbols | 22 +++ .../reference/predicateSemantics.types | 66 +++++++++ ...aryOperatorsOnExportedVariables.errors.txt | 4 +- .../reference/primitiveMembers.errors.txt | 4 +- .../reference/shebangError.errors.txt | 4 +- ...gLiteralsWithSwitchStatements03.errors.txt | 16 +-- ...gLiteralsWithSwitchStatements04.errors.txt | 20 +-- .../reference/symbolType11.errors.txt | 4 +- .../typeGuardsInIfStatement.errors.txt | 4 +- .../reference/voidAsOperator.errors.txt | 4 +- tests/baselines/reference/witness.errors.txt | 8 +- tests/cases/compiler/predicateSemantics.ts | 11 ++ 60 files changed, 564 insertions(+), 392 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 492a59bccccb2..c2e888d865d6d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -39566,8 +39566,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } const leftTarget = skipOuterExpressions(left, OuterExpressionKinds.All); - if (getSyntacticNullishnessSemantics(leftTarget) !== PredicateSemantics.Sometimes) { - error(leftTarget, Diagnostics.Using_on_this_expression_appears_unintentional_because_it_always_evaluates_to_the_same_nullishness); + const nullishSemantics = getSyntacticNullishnessSemantics(leftTarget); + if (nullishSemantics !== PredicateSemantics.Sometimes) { + if (node.parent.kind === SyntaxKind.BinaryExpression) { + error(leftTarget, Diagnostics.This_binary_expression_is_never_nullish_Are_you_missing_parentheses); + } + else { + if (nullishSemantics === PredicateSemantics.Always) { + error(leftTarget, Diagnostics.This_expression_is_always_nullish); + } + else { + error(leftTarget, Diagnostics.Right_operand_of_is_unreachable_because_the_left_operand_is_never_nullish); + } + } } } } @@ -44250,8 +44261,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { error( node, semantics === PredicateSemantics.Always ? - Diagnostics.This_expression_is_always_truthy_Did_you_mean_to_test_something_else : - Diagnostics.This_expression_is_always_falsy_Did_you_mean_to_test_something_else, + Diagnostics.This_kind_of_expression_is_always_truthy : + Diagnostics.This_kind_of_expression_is_always_falsy ); } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 2e06af5f8e9c3..93f6d63c74e79 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3911,19 +3911,26 @@ "category": "Error", "code": 2868 }, - "This expression is always truthy. Did you mean to test something else?": { + "Right operand of ?? is unreachable because the left operand is never nullish.": { "category": "Error", "code": 2869 }, - "This expression is always falsy. Did you mean to test something else?": { + "This binary expression is never nullish. Are you missing parentheses?": { "category": "Error", "code": 2870 }, - "Using ?? on this expression appears unintentional because it always evaluates to the same nullishness.": { + "This expression is always nullish.": { "category": "Error", "code": 2871 }, - + "This kind of expression is always truthy.": { + "category": "Error", + "code": 2872 + }, + "This kind of expression is always falsy.": { + "category": "Error", + "code": 2873 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 diff --git a/tests/baselines/reference/checkJsdocReturnTag1.errors.txt b/tests/baselines/reference/checkJsdocReturnTag1.errors.txt index c2910d41f5030..47f1a3209dede 100644 --- a/tests/baselines/reference/checkJsdocReturnTag1.errors.txt +++ b/tests/baselines/reference/checkJsdocReturnTag1.errors.txt @@ -1,4 +1,4 @@ -returns.js(20,12): error TS2869: This expression is always truthy. Did you mean to test something else? +returns.js(20,12): error TS2872: This kind of expression is always truthy. ==== returns.js (1 errors) ==== @@ -23,6 +23,6 @@ returns.js(20,12): error TS2869: This expression is always truthy. Did you mean function f2() { return 5 || "hello"; ~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. } \ No newline at end of file diff --git a/tests/baselines/reference/checkJsdocReturnTag2.errors.txt b/tests/baselines/reference/checkJsdocReturnTag2.errors.txt index 4ac177cc3233c..c5ab204ed8438 100644 --- a/tests/baselines/reference/checkJsdocReturnTag2.errors.txt +++ b/tests/baselines/reference/checkJsdocReturnTag2.errors.txt @@ -1,7 +1,7 @@ returns.js(6,5): error TS2322: Type 'number' is not assignable to type 'string'. returns.js(13,5): error TS2322: Type 'number | boolean' is not assignable to type 'string | number'. Type 'boolean' is not assignable to type 'string | number'. -returns.js(13,12): error TS2869: This expression is always truthy. Did you mean to test something else? +returns.js(13,12): error TS2872: This kind of expression is always truthy. ==== returns.js (3 errors) ==== @@ -24,6 +24,6 @@ returns.js(13,12): error TS2869: This expression is always truthy. Did you mean !!! error TS2322: Type 'number | boolean' is not assignable to type 'string | number'. !!! error TS2322: Type 'boolean' is not assignable to type 'string | number'. ~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames46_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames46_ES5.errors.txt index aea4963dd8754..8b574a3610e6f 100644 --- a/tests/baselines/reference/computedPropertyNames46_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames46_ES5.errors.txt @@ -1,9 +1,9 @@ -computedPropertyNames46_ES5.ts(2,6): error TS2870: This expression is always falsy. Did you mean to test something else? +computedPropertyNames46_ES5.ts(2,6): error TS2873: This kind of expression is always falsy. ==== computedPropertyNames46_ES5.ts (1 errors) ==== var o = { ["" || 0]: 0 ~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. }; \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames46_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames46_ES6.errors.txt index b3efc06a9dea2..67c2d8c7cdeac 100644 --- a/tests/baselines/reference/computedPropertyNames46_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNames46_ES6.errors.txt @@ -1,9 +1,9 @@ -computedPropertyNames46_ES6.ts(2,6): error TS2870: This expression is always falsy. Did you mean to test something else? +computedPropertyNames46_ES6.ts(2,6): error TS2873: This kind of expression is always falsy. ==== computedPropertyNames46_ES6.ts (1 errors) ==== var o = { ["" || 0]: 0 ~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. }; \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames48_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames48_ES5.errors.txt index 00d1841816315..4cbb21c322842 100644 --- a/tests/baselines/reference/computedPropertyNames48_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames48_ES5.errors.txt @@ -1,4 +1,4 @@ -computedPropertyNames48_ES5.ts(16,6): error TS2870: This expression is always falsy. Did you mean to test something else? +computedPropertyNames48_ES5.ts(16,6): error TS2873: This kind of expression is always falsy. ==== computedPropertyNames48_ES5.ts (1 errors) ==== @@ -19,5 +19,5 @@ computedPropertyNames48_ES5.ts(16,6): error TS2870: This expression is always fa extractIndexer({ ["" || 0]: "" ~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. }); // Should return any (widened form of undefined) \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames48_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames48_ES6.errors.txt index f26c5092f6b55..b4d5d245b7128 100644 --- a/tests/baselines/reference/computedPropertyNames48_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNames48_ES6.errors.txt @@ -1,4 +1,4 @@ -computedPropertyNames48_ES6.ts(16,6): error TS2870: This expression is always falsy. Did you mean to test something else? +computedPropertyNames48_ES6.ts(16,6): error TS2873: This kind of expression is always falsy. ==== computedPropertyNames48_ES6.ts (1 errors) ==== @@ -19,5 +19,5 @@ computedPropertyNames48_ES6.ts(16,6): error TS2870: This expression is always fa extractIndexer({ ["" || 0]: "" ~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. }); // Should return any (widened form of undefined) \ No newline at end of file diff --git a/tests/baselines/reference/conditionalOperatorConditionIsNumberType.errors.txt b/tests/baselines/reference/conditionalOperatorConditionIsNumberType.errors.txt index 85db59cd34926..dfc26d8324850 100644 --- a/tests/baselines/reference/conditionalOperatorConditionIsNumberType.errors.txt +++ b/tests/baselines/reference/conditionalOperatorConditionIsNumberType.errors.txt @@ -1,9 +1,9 @@ -conditionalOperatorConditionIsNumberType.ts(27,1): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsNumberType.ts(29,1): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsNumberType.ts(30,1): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsNumberType.ts(53,23): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsNumberType.ts(55,23): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsNumberType.ts(56,32): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsNumberType.ts(27,1): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditionIsNumberType.ts(29,1): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditionIsNumberType.ts(30,1): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditionIsNumberType.ts(53,23): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditionIsNumberType.ts(55,23): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditionIsNumberType.ts(56,32): error TS2872: This kind of expression is always truthy. ==== conditionalOperatorConditionIsNumberType.ts (6 errors) ==== @@ -35,14 +35,14 @@ conditionalOperatorConditionIsNumberType.ts(56,32): error TS2869: This expressio 0 ? exprBoolean1 : exprBoolean2; 0.123456789 ? exprNumber1 : exprNumber2; ~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. - 10000000000000 ? exprString1 : exprString2; 1000000000000 ? exprIsObject1 : exprIsObject2; ~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. 10000 ? exprString1 : exprBoolean1; // Union ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. //Cond is a number type expression function foo() { return 1 }; @@ -67,14 +67,14 @@ conditionalOperatorConditionIsNumberType.ts(56,32): error TS2869: This expressio var resultIsBoolean2 = 0 ? exprBoolean1 : exprBoolean2; var resultIsNumber2 = 0.123456789 ? exprNumber1 : exprNumber2; ~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var resultIsString2 = - 10000000000000 ? exprString1 : exprString2; var resultIsObject2 = 1000000000000 ? exprIsObject1 : exprIsObject2; ~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var resultIsStringOrBoolean2 = 10000 ? exprString1 : exprBoolean1; // Union ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var resultIsAny3 = 1 * 0 ? exprAny1 : exprAny2; var resultIsBoolean3 = 1 + 1 ? exprBoolean1 : exprBoolean2; diff --git a/tests/baselines/reference/conditionalOperatorConditionIsObjectType.errors.txt b/tests/baselines/reference/conditionalOperatorConditionIsObjectType.errors.txt index c72262b12182f..d5388838074c9 100644 --- a/tests/baselines/reference/conditionalOperatorConditionIsObjectType.errors.txt +++ b/tests/baselines/reference/conditionalOperatorConditionIsObjectType.errors.txt @@ -1,17 +1,17 @@ -conditionalOperatorConditionIsObjectType.ts(28,1): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsObjectType.ts(29,1): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsObjectType.ts(30,1): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsObjectType.ts(31,1): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsObjectType.ts(32,1): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsObjectType.ts(33,1): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(28,1): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditionIsObjectType.ts(29,1): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditionIsObjectType.ts(30,1): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditionIsObjectType.ts(31,1): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditionIsObjectType.ts(32,1): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditionIsObjectType.ts(33,1): error TS2872: This kind of expression is always truthy. conditionalOperatorConditionIsObjectType.ts(36,1): error TS1345: An expression of type 'void' cannot be tested for truthiness. conditionalOperatorConditionIsObjectType.ts(39,1): error TS1345: An expression of type 'void' cannot be tested for truthiness. -conditionalOperatorConditionIsObjectType.ts(51,20): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsObjectType.ts(52,24): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsObjectType.ts(53,23): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsObjectType.ts(54,23): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsObjectType.ts(55,23): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditionIsObjectType.ts(56,32): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditionIsObjectType.ts(51,20): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditionIsObjectType.ts(52,24): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditionIsObjectType.ts(53,23): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditionIsObjectType.ts(54,23): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditionIsObjectType.ts(55,23): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditionIsObjectType.ts(56,32): error TS2872: This kind of expression is always truthy. conditionalOperatorConditionIsObjectType.ts(58,20): error TS1345: An expression of type 'void' cannot be tested for truthiness. conditionalOperatorConditionIsObjectType.ts(61,23): error TS1345: An expression of type 'void' cannot be tested for truthiness. conditionalOperatorConditionIsObjectType.ts(63,32): error TS1345: An expression of type 'void' cannot be tested for truthiness. @@ -47,22 +47,22 @@ conditionalOperatorConditionIsObjectType.ts(63,32): error TS1345: An expression //Cond is an object type literal ((a: string) => a.length) ? exprAny1 : exprAny2; ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. ((a: string) => a.length) ? exprBoolean1 : exprBoolean2; ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. ({}) ? exprNumber1 : exprNumber2; ~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. ({ a: 1, b: "s" }) ? exprString1 : exprString2; ~~~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. ({ a: 1, b: "s" }) ? exprIsObject1 : exprIsObject2; ~~~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. ({ a: 1, b: "s" }) ? exprString1: exprBoolean1; // union ~~~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. //Cond is an object type expression foo() ? exprAny1 : exprAny2; @@ -86,22 +86,22 @@ conditionalOperatorConditionIsObjectType.ts(63,32): error TS1345: An expression var resultIsAny2 = ((a: string) => a.length) ? exprAny1 : exprAny2; ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var resultIsBoolean2 = ((a: string) => a.length) ? exprBoolean1 : exprBoolean2; ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var resultIsNumber2 = ({}) ? exprNumber1 : exprNumber2; ~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var resultIsString2 = ({ a: 1, b: "s" }) ? exprString1 : exprString2; ~~~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var resultIsObject2 = ({ a: 1, b: "s" }) ? exprIsObject1 : exprIsObject2; ~~~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var resultIsStringOrBoolean2 = ({ a: 1, b: "s" }) ? exprString1 : exprBoolean1; // union ~~~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var resultIsAny3 = foo() ? exprAny1 : exprAny2; ~~~~~ diff --git a/tests/baselines/reference/conditionalOperatorConditoinIsAnyType.errors.txt b/tests/baselines/reference/conditionalOperatorConditoinIsAnyType.errors.txt index 4449dbe66fcff..a42ed0393085a 100644 --- a/tests/baselines/reference/conditionalOperatorConditoinIsAnyType.errors.txt +++ b/tests/baselines/reference/conditionalOperatorConditoinIsAnyType.errors.txt @@ -1,12 +1,12 @@ -conditionalOperatorConditoinIsAnyType.ts(28,1): error TS2870: This expression is always falsy. Did you mean to test something else? -conditionalOperatorConditoinIsAnyType.ts(29,1): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditoinIsAnyType.ts(30,1): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditoinIsAnyType.ts(31,1): error TS2870: This expression is always falsy. Did you mean to test something else? -conditionalOperatorConditoinIsAnyType.ts(51,23): error TS2870: This expression is always falsy. Did you mean to test something else? -conditionalOperatorConditoinIsAnyType.ts(52,23): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditoinIsAnyType.ts(53,23): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditoinIsAnyType.ts(55,32): error TS2870: This expression is always falsy. Did you mean to test something else? -conditionalOperatorConditoinIsAnyType.ts(56,32): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditoinIsAnyType.ts(28,1): error TS2873: This kind of expression is always falsy. +conditionalOperatorConditoinIsAnyType.ts(29,1): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditoinIsAnyType.ts(30,1): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditoinIsAnyType.ts(31,1): error TS2873: This kind of expression is always falsy. +conditionalOperatorConditoinIsAnyType.ts(51,23): error TS2873: This kind of expression is always falsy. +conditionalOperatorConditoinIsAnyType.ts(52,23): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditoinIsAnyType.ts(53,23): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditoinIsAnyType.ts(55,32): error TS2873: This kind of expression is always falsy. +conditionalOperatorConditoinIsAnyType.ts(56,32): error TS2872: This kind of expression is always truthy. ==== conditionalOperatorConditoinIsAnyType.ts (9 errors) ==== @@ -39,16 +39,16 @@ conditionalOperatorConditoinIsAnyType.ts(56,32): error TS2869: This expression i null ? exprBoolean1 : exprBoolean2; undefined ? exprNumber1 : exprNumber2; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. [null, undefined] ? exprString1 : exprString2; ~~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. [null, undefined] ? exprIsObject1 : exprIsObject2; ~~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. undefined ? exprString1 : exprBoolean1; // union ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. //Cond is an any type expression x.doSomeThing() ? exprAny1 : exprAny2; @@ -70,20 +70,20 @@ conditionalOperatorConditoinIsAnyType.ts(56,32): error TS2869: This expression i var resultIsBoolean2 = null ? exprBoolean1 : exprBoolean2; var resultIsNumber2 = undefined ? exprNumber1 : exprNumber2; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var resultIsString2 = [null, undefined] ? exprString1 : exprString2; ~~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var resultIsObject2 = [null, undefined] ? exprIsObject1 : exprIsObject2; ~~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var resultIsStringOrBoolean2 = null ? exprString1 : exprBoolean1; // union var resultIsStringOrBoolean3 = undefined ? exprString1 : exprBoolean1; // union ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var resultIsStringOrBoolean4 = [null, undefined] ? exprString1 : exprBoolean1; // union ~~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var resultIsAny3 = x.doSomeThing() ? exprAny1 : exprAny2; var resultIsBoolean3 = x("x") ? exprBoolean1 : exprBoolean2; diff --git a/tests/baselines/reference/conditionalOperatorConditoinIsStringType.errors.txt b/tests/baselines/reference/conditionalOperatorConditoinIsStringType.errors.txt index ea5d8e13427a8..efccbc8e2d291 100644 --- a/tests/baselines/reference/conditionalOperatorConditoinIsStringType.errors.txt +++ b/tests/baselines/reference/conditionalOperatorConditoinIsStringType.errors.txt @@ -1,15 +1,15 @@ -conditionalOperatorConditoinIsStringType.ts(25,1): error TS2870: This expression is always falsy. Did you mean to test something else? -conditionalOperatorConditoinIsStringType.ts(26,1): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditoinIsStringType.ts(27,1): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditoinIsStringType.ts(28,1): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditoinIsStringType.ts(29,1): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditoinIsStringType.ts(30,1): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditoinIsStringType.ts(51,20): error TS2870: This expression is always falsy. Did you mean to test something else? -conditionalOperatorConditoinIsStringType.ts(52,24): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditoinIsStringType.ts(53,23): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditoinIsStringType.ts(54,23): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditoinIsStringType.ts(55,23): error TS2869: This expression is always truthy. Did you mean to test something else? -conditionalOperatorConditoinIsStringType.ts(56,32): error TS2869: This expression is always truthy. Did you mean to test something else? +conditionalOperatorConditoinIsStringType.ts(25,1): error TS2873: This kind of expression is always falsy. +conditionalOperatorConditoinIsStringType.ts(26,1): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditoinIsStringType.ts(27,1): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditoinIsStringType.ts(28,1): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditoinIsStringType.ts(29,1): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditoinIsStringType.ts(30,1): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditoinIsStringType.ts(51,20): error TS2873: This kind of expression is always falsy. +conditionalOperatorConditoinIsStringType.ts(52,24): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditoinIsStringType.ts(53,23): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditoinIsStringType.ts(54,23): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditoinIsStringType.ts(55,23): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditoinIsStringType.ts(56,32): error TS2872: This kind of expression is always truthy. ==== conditionalOperatorConditoinIsStringType.ts (12 errors) ==== @@ -39,22 +39,22 @@ conditionalOperatorConditoinIsStringType.ts(56,32): error TS2869: This expressio //Cond is a string type literal "" ? exprAny1 : exprAny2; ~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. "string" ? exprBoolean1 : exprBoolean2; ~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. 'c' ? exprNumber1 : exprNumber2; ~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. 'string' ? exprString1 : exprString2; ~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. " " ? exprIsObject1 : exprIsObject2; ~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. "hello " ? exprString1 : exprBoolean1; // union ~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. //Cond is a string type expression function foo() { return "string" }; @@ -77,22 +77,22 @@ conditionalOperatorConditoinIsStringType.ts(56,32): error TS2869: This expressio var resultIsAny2 = "" ? exprAny1 : exprAny2; ~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var resultIsBoolean2 = "string" ? exprBoolean1 : exprBoolean2; ~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var resultIsNumber2 = 'c' ? exprNumber1 : exprNumber2; ~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var resultIsString2 = 'string' ? exprString1 : exprString2; ~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var resultIsObject2 = " " ? exprIsObject1 : exprIsObject2; ~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var resultIsStringOrBoolean2 = "hello" ? exprString1 : exprBoolean1; // union ~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var resultIsAny3 = typeof condString ? exprAny1 : exprAny2; var resultIsBoolean3 = condString.toUpperCase ? exprBoolean1 : exprBoolean2; diff --git a/tests/baselines/reference/constEnum4.errors.txt b/tests/baselines/reference/constEnum4.errors.txt index 8cb45b4573c52..87a9bc65f55fe 100644 --- a/tests/baselines/reference/constEnum4.errors.txt +++ b/tests/baselines/reference/constEnum4.errors.txt @@ -1,4 +1,4 @@ -constEnum4.ts(3,10): error TS2869: This expression is always truthy. Did you mean to test something else? +constEnum4.ts(3,10): error TS2872: This kind of expression is always truthy. ==== constEnum4.ts (1 errors) ==== @@ -6,7 +6,7 @@ constEnum4.ts(3,10): error TS2869: This expression is always truthy. Did you mea const enum A { } else if (2) ~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. const enum B { } else const enum C { } diff --git a/tests/baselines/reference/contextuallyTypeLogicalAnd03.errors.txt b/tests/baselines/reference/contextuallyTypeLogicalAnd03.errors.txt index 31b1e727b878b..62db2fc1eb96f 100644 --- a/tests/baselines/reference/contextuallyTypeLogicalAnd03.errors.txt +++ b/tests/baselines/reference/contextuallyTypeLogicalAnd03.errors.txt @@ -1,4 +1,4 @@ -contextuallyTypeLogicalAnd03.ts(4,5): error TS2869: This expression is always truthy. Did you mean to test something else? +contextuallyTypeLogicalAnd03.ts(4,5): error TS2872: This kind of expression is always truthy. contextuallyTypeLogicalAnd03.ts(4,6): error TS7006: Parameter 'a' implicitly has an 'any' type. @@ -8,6 +8,6 @@ contextuallyTypeLogicalAnd03.ts(4,6): error TS7006: Parameter 'a' implicitly has x = (a => a) && (b => b); ~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. ~ !!! error TS7006: Parameter 'a' implicitly has an 'any' type. \ No newline at end of file diff --git a/tests/baselines/reference/contextuallyTypingOrOperator.errors.txt b/tests/baselines/reference/contextuallyTypingOrOperator.errors.txt index ccb12aa6dc6f9..6920951965060 100644 --- a/tests/baselines/reference/contextuallyTypingOrOperator.errors.txt +++ b/tests/baselines/reference/contextuallyTypingOrOperator.errors.txt @@ -1,10 +1,10 @@ -contextuallyTypingOrOperator.ts(1,39): error TS2869: This expression is always truthy. Did you mean to test something else? +contextuallyTypingOrOperator.ts(1,39): error TS2872: This kind of expression is always truthy. ==== contextuallyTypingOrOperator.ts (1 errors) ==== var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 }; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var v2 = (s: string) => s.length || function (s) { s.length }; diff --git a/tests/baselines/reference/contextuallyTypingOrOperator2.errors.txt b/tests/baselines/reference/contextuallyTypingOrOperator2.errors.txt index 00955c9ead550..e7af25339e55a 100644 --- a/tests/baselines/reference/contextuallyTypingOrOperator2.errors.txt +++ b/tests/baselines/reference/contextuallyTypingOrOperator2.errors.txt @@ -1,9 +1,9 @@ -contextuallyTypingOrOperator2.ts(1,39): error TS2869: This expression is always truthy. Did you mean to test something else? +contextuallyTypingOrOperator2.ts(1,39): error TS2872: This kind of expression is always truthy. ==== contextuallyTypingOrOperator2.ts (1 errors) ==== var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 }; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var v2 = (s: string) => s.length || function (s) { s.aaa }; \ No newline at end of file diff --git a/tests/baselines/reference/controlFlowForStatement.errors.txt b/tests/baselines/reference/controlFlowForStatement.errors.txt index db1f9e0616d1d..b45976464a3bd 100644 --- a/tests/baselines/reference/controlFlowForStatement.errors.txt +++ b/tests/baselines/reference/controlFlowForStatement.errors.txt @@ -1,5 +1,5 @@ -controlFlowForStatement.ts(29,14): error TS2870: This expression is always falsy. Did you mean to test something else? -controlFlowForStatement.ts(29,50): error TS2870: This expression is always falsy. Did you mean to test something else? +controlFlowForStatement.ts(29,14): error TS2873: This kind of expression is always falsy. +controlFlowForStatement.ts(29,50): error TS2873: This kind of expression is always falsy. ==== controlFlowForStatement.ts (2 errors) ==== @@ -33,9 +33,9 @@ controlFlowForStatement.ts(29,50): error TS2870: This expression is always falsy let x: string | number | boolean | RegExp; for (x = "" || 0; typeof x !== "string"; x = "" || true) { ~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. ~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. x; // number | boolean } } diff --git a/tests/baselines/reference/declFileTypeAnnotationParenType.errors.txt b/tests/baselines/reference/declFileTypeAnnotationParenType.errors.txt index 8828e7fa0f576..662ed01ca8883 100644 --- a/tests/baselines/reference/declFileTypeAnnotationParenType.errors.txt +++ b/tests/baselines/reference/declFileTypeAnnotationParenType.errors.txt @@ -1,5 +1,5 @@ -declFileTypeAnnotationParenType.ts(8,29): error TS2869: This expression is always truthy. Did you mean to test something else? -declFileTypeAnnotationParenType.ts(9,9): error TS2869: This expression is always truthy. Did you mean to test something else? +declFileTypeAnnotationParenType.ts(8,29): error TS2872: This kind of expression is always truthy. +declFileTypeAnnotationParenType.ts(9,9): error TS2872: This kind of expression is always truthy. ==== declFileTypeAnnotationParenType.ts (2 errors) ==== @@ -12,7 +12,7 @@ declFileTypeAnnotationParenType.ts(9,9): error TS2869: This expression is always var k: (() => c) | string = (() => new c()) || ""; ~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var l = (() => new c()) || ""; ~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? \ No newline at end of file +!!! error TS2872: This kind of expression is always truthy. \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitInferredTypeAlias1.errors.txt b/tests/baselines/reference/declarationEmitInferredTypeAlias1.errors.txt index 063ec3cf0bcc8..5e772022364c2 100644 --- a/tests/baselines/reference/declarationEmitInferredTypeAlias1.errors.txt +++ b/tests/baselines/reference/declarationEmitInferredTypeAlias1.errors.txt @@ -1,4 +1,4 @@ -1.ts(1,9): error TS2869: This expression is always truthy. Did you mean to test something else? +1.ts(1,9): error TS2872: This kind of expression is always truthy. ==== 0.ts (0 errors) ==== @@ -11,5 +11,5 @@ ==== 1.ts (1 errors) ==== let v = "str" || true; ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. export { v } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitInferredTypeAlias2.errors.txt b/tests/baselines/reference/declarationEmitInferredTypeAlias2.errors.txt index c63af018e1205..c35dd49cb85af 100644 --- a/tests/baselines/reference/declarationEmitInferredTypeAlias2.errors.txt +++ b/tests/baselines/reference/declarationEmitInferredTypeAlias2.errors.txt @@ -1,4 +1,4 @@ -1.ts(1,9): error TS2869: This expression is always truthy. Did you mean to test something else? +1.ts(1,9): error TS2872: This kind of expression is always truthy. ==== 0.ts (0 errors) ==== @@ -11,7 +11,7 @@ ==== 1.ts (1 errors) ==== let v = "str" || true; ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. function bar () { return v; } diff --git a/tests/baselines/reference/declarationEmitInferredTypeAlias3.errors.txt b/tests/baselines/reference/declarationEmitInferredTypeAlias3.errors.txt index ec2a2a63fe98f..435cfb255ae40 100644 --- a/tests/baselines/reference/declarationEmitInferredTypeAlias3.errors.txt +++ b/tests/baselines/reference/declarationEmitInferredTypeAlias3.errors.txt @@ -1,4 +1,4 @@ -1.ts(1,9): error TS2869: This expression is always truthy. Did you mean to test something else? +1.ts(1,9): error TS2872: This kind of expression is always truthy. ==== 0.ts (0 errors) ==== @@ -11,5 +11,5 @@ ==== 1.ts (1 errors) ==== var x = "hi" || 5; ~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. export default x; \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitInferredTypeAlias5.errors.txt b/tests/baselines/reference/declarationEmitInferredTypeAlias5.errors.txt index 7ddcc8ef2b952..bd19e41149f02 100644 --- a/tests/baselines/reference/declarationEmitInferredTypeAlias5.errors.txt +++ b/tests/baselines/reference/declarationEmitInferredTypeAlias5.errors.txt @@ -1,4 +1,4 @@ -1.ts(3,9): error TS2869: This expression is always truthy. Did you mean to test something else? +1.ts(3,9): error TS2872: This kind of expression is always truthy. ==== 0.ts (0 errors) ==== @@ -10,5 +10,5 @@ //let v2: Z.Data; let v = "str" || true; ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. export { v } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitInferredTypeAlias6.errors.txt b/tests/baselines/reference/declarationEmitInferredTypeAlias6.errors.txt index 063ec3cf0bcc8..5e772022364c2 100644 --- a/tests/baselines/reference/declarationEmitInferredTypeAlias6.errors.txt +++ b/tests/baselines/reference/declarationEmitInferredTypeAlias6.errors.txt @@ -1,4 +1,4 @@ -1.ts(1,9): error TS2869: This expression is always truthy. Did you mean to test something else? +1.ts(1,9): error TS2872: This kind of expression is always truthy. ==== 0.ts (0 errors) ==== @@ -11,5 +11,5 @@ ==== 1.ts (1 errors) ==== let v = "str" || true; ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. export { v } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitInferredTypeAlias7.errors.txt b/tests/baselines/reference/declarationEmitInferredTypeAlias7.errors.txt index 618246f0e3b82..e0ea531e75e70 100644 --- a/tests/baselines/reference/declarationEmitInferredTypeAlias7.errors.txt +++ b/tests/baselines/reference/declarationEmitInferredTypeAlias7.errors.txt @@ -1,4 +1,4 @@ -1.ts(1,9): error TS2869: This expression is always truthy. Did you mean to test something else? +1.ts(1,9): error TS2872: This kind of expression is always truthy. ==== 0.ts (0 errors) ==== @@ -8,5 +8,5 @@ ==== 1.ts (1 errors) ==== let v = "str" || true; ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. export { v } \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterProperties1.errors.txt b/tests/baselines/reference/destructuringParameterProperties1.errors.txt index a400cf02515d8..ab7a1f38d7172 100644 --- a/tests/baselines/reference/destructuringParameterProperties1.errors.txt +++ b/tests/baselines/reference/destructuringParameterProperties1.errors.txt @@ -5,7 +5,7 @@ destructuringParameterProperties1.ts(22,26): error TS2339: Property 'x' does not destructuringParameterProperties1.ts(22,35): error TS2339: Property 'y' does not exist on type 'C1'. destructuringParameterProperties1.ts(22,43): error TS2339: Property 'y' does not exist on type 'C1'. destructuringParameterProperties1.ts(22,52): error TS2339: Property 'z' does not exist on type 'C1'. -destructuringParameterProperties1.ts(24,30): error TS2869: This expression is always truthy. Did you mean to test something else? +destructuringParameterProperties1.ts(24,30): error TS2872: This kind of expression is always truthy. destructuringParameterProperties1.ts(25,30): error TS2339: Property 'x' does not exist on type 'C2'. destructuringParameterProperties1.ts(25,36): error TS2339: Property 'y' does not exist on type 'C2'. destructuringParameterProperties1.ts(25,42): error TS2339: Property 'z' does not exist on type 'C2'. @@ -54,7 +54,7 @@ destructuringParameterProperties1.ts(29,42): error TS2339: Property 'z' does not var c2 = new C2(["10", 10, !!10]); ~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var [c2_x, c2_y, c2_z] = [c2.x, c2.y, c2.z]; ~ !!! error TS2339: Property 'x' does not exist on type 'C2'. diff --git a/tests/baselines/reference/exponentiationOperatorSyntaxError2.errors.txt b/tests/baselines/reference/exponentiationOperatorSyntaxError2.errors.txt index 91ada32050f74..2f336cc9eaea7 100644 --- a/tests/baselines/reference/exponentiationOperatorSyntaxError2.errors.txt +++ b/tests/baselines/reference/exponentiationOperatorSyntaxError2.errors.txt @@ -78,7 +78,7 @@ exponentiationOperatorSyntaxError2.ts(52,1): error TS2362: The left-hand side of exponentiationOperatorSyntaxError2.ts(52,1): error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. exponentiationOperatorSyntaxError2.ts(53,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorSyntaxError2.ts(53,1): error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -exponentiationOperatorSyntaxError2.ts(53,2): error TS2869: This expression is always truthy. Did you mean to test something else? +exponentiationOperatorSyntaxError2.ts(53,2): error TS2872: This kind of expression is always truthy. exponentiationOperatorSyntaxError2.ts(54,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorSyntaxError2.ts(54,1): error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. exponentiationOperatorSyntaxError2.ts(55,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. @@ -89,7 +89,7 @@ exponentiationOperatorSyntaxError2.ts(58,6): error TS2362: The left-hand side of exponentiationOperatorSyntaxError2.ts(58,6): error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. exponentiationOperatorSyntaxError2.ts(59,6): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorSyntaxError2.ts(59,6): error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -exponentiationOperatorSyntaxError2.ts(59,7): error TS2869: This expression is always truthy. Did you mean to test something else? +exponentiationOperatorSyntaxError2.ts(59,7): error TS2872: This kind of expression is always truthy. exponentiationOperatorSyntaxError2.ts(60,6): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorSyntaxError2.ts(60,6): error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. exponentiationOperatorSyntaxError2.ts(61,6): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. @@ -316,7 +316,7 @@ exponentiationOperatorSyntaxError2.ts(67,1): error TS17007: A type assertion exp ~~ !!! error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. ~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. !temp++ ** 4; ~~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. @@ -344,7 +344,7 @@ exponentiationOperatorSyntaxError2.ts(67,1): error TS17007: A type assertion exp ~~ !!! error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. ~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. 1 ** !temp++ ** 4; ~~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. diff --git a/tests/baselines/reference/exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.errors.txt b/tests/baselines/reference/exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.errors.txt index 7e79af572ccfc..54c143bc49ab9 100644 --- a/tests/baselines/reference/exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.errors.txt +++ b/tests/baselines/reference/exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.errors.txt @@ -1,13 +1,13 @@ exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(4,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(5,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(6,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. -exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(6,3): error TS2869: This expression is always truthy. Did you mean to test something else? +exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(6,3): error TS2872: This kind of expression is always truthy. exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(7,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(8,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(10,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(11,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(12,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. -exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(12,3): error TS2869: This expression is always truthy. Did you mean to test something else? +exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(12,3): error TS2872: This kind of expression is always truthy. exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(13,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(14,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(16,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. @@ -52,7 +52,7 @@ exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(36,14): error ~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. ~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. (!temp++) ** 4; ~~~~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. @@ -70,7 +70,7 @@ exponentiationOperatorWithInvalidSimpleUnaryExpressionOperands.ts(36,14): error ~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. ~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. (!temp++) ** 4 ** 1; ~~~~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. diff --git a/tests/baselines/reference/fatarrowfunctionsOptionalArgs.errors.txt b/tests/baselines/reference/fatarrowfunctionsOptionalArgs.errors.txt index 3cb838d4945bc..971f0fedccedf 100644 --- a/tests/baselines/reference/fatarrowfunctionsOptionalArgs.errors.txt +++ b/tests/baselines/reference/fatarrowfunctionsOptionalArgs.errors.txt @@ -1,4 +1,4 @@ -fatarrowfunctionsOptionalArgs.ts(85,1): error TS2869: This expression is always truthy. Did you mean to test something else? +fatarrowfunctionsOptionalArgs.ts(85,1): error TS2872: This kind of expression is always truthy. fatarrowfunctionsOptionalArgs.ts(88,23): error TS1005: ';' expected. fatarrowfunctionsOptionalArgs.ts(88,38): error TS1005: ';' expected. @@ -90,7 +90,7 @@ fatarrowfunctionsOptionalArgs.ts(88,38): error TS1005: ';' expected. // nested ternary expressions ((a?) => { return a; }) ? (b? ) => { return b; } : (c? ) => { return c; }; ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. //multiple levels (a?) => { return a; } ? (b)=>(c)=>81 : (c)=>(d)=>82; diff --git a/tests/baselines/reference/for-inStatements.errors.txt b/tests/baselines/reference/for-inStatements.errors.txt index c5a632ea04a3b..530e47fd2f89c 100644 --- a/tests/baselines/reference/for-inStatements.errors.txt +++ b/tests/baselines/reference/for-inStatements.errors.txt @@ -1,6 +1,6 @@ -for-inStatements.ts(21,15): error TS2869: This expression is always truthy. Did you mean to test something else? -for-inStatements.ts(22,15): error TS2870: This expression is always falsy. Did you mean to test something else? -for-inStatements.ts(23,15): error TS2869: This expression is always truthy. Did you mean to test something else? +for-inStatements.ts(21,15): error TS2872: This kind of expression is always truthy. +for-inStatements.ts(22,15): error TS2873: This kind of expression is always falsy. +for-inStatements.ts(23,15): error TS2872: This kind of expression is always truthy. for-inStatements.ts(33,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'Extract'. for-inStatements.ts(50,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'Extract'. for-inStatements.ts(79,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'Color.Blue'. @@ -29,13 +29,13 @@ for-inStatements.ts(79,15): error TS2407: The right-hand side of a 'for...in' st for (var x in e ? c : d) { } for (var x in 42 ? c : d) { } ~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. for (var x in '' ? c : d) { } ~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. for (var x in 42 ? d[x] : c[x]) { } ~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. for (var x in c[d]) { } for (var x in ((x: T) => x)) { } diff --git a/tests/baselines/reference/for-inStatementsInvalid.errors.txt b/tests/baselines/reference/for-inStatementsInvalid.errors.txt index 30d16b2b32a39..2ff7d19443911 100644 --- a/tests/baselines/reference/for-inStatementsInvalid.errors.txt +++ b/tests/baselines/reference/for-inStatementsInvalid.errors.txt @@ -5,11 +5,11 @@ for-inStatementsInvalid.ts(10,10): error TS2404: The left-hand side of a 'for... for-inStatementsInvalid.ts(13,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'void'. for-inStatementsInvalid.ts(17,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'string'. for-inStatementsInvalid.ts(18,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'string'. -for-inStatementsInvalid.ts(19,15): error TS2869: This expression is always truthy. Did you mean to test something else? +for-inStatementsInvalid.ts(19,15): error TS2872: This kind of expression is always truthy. for-inStatementsInvalid.ts(19,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'string'. -for-inStatementsInvalid.ts(20,15): error TS2870: This expression is always falsy. Did you mean to test something else? +for-inStatementsInvalid.ts(20,15): error TS2873: This kind of expression is always falsy. for-inStatementsInvalid.ts(20,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'string'. -for-inStatementsInvalid.ts(21,15): error TS2869: This expression is always truthy. Did you mean to test something else? +for-inStatementsInvalid.ts(21,15): error TS2872: This kind of expression is always truthy. for-inStatementsInvalid.ts(22,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'string'. for-inStatementsInvalid.ts(29,23): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'number'. for-inStatementsInvalid.ts(31,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'Extract'. @@ -55,17 +55,17 @@ for-inStatementsInvalid.ts(62,15): error TS2407: The right-hand side of a 'for.. !!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'string'. for (var x in 42 ? c : d) { } ~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. ~~~~~~~~~~ !!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'string'. for (var x in '' ? c : d) { } ~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. ~~~~~~~~~~ !!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'string'. for (var x in 42 ? d[x] : c[x]) { } ~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. for (var x in c[23]) { } ~~~~~ !!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'string'. diff --git a/tests/baselines/reference/generatedContextualTyping.errors.txt b/tests/baselines/reference/generatedContextualTyping.errors.txt index 809ebb5c7d0f1..a33af3a894608 100644 --- a/tests/baselines/reference/generatedContextualTyping.errors.txt +++ b/tests/baselines/reference/generatedContextualTyping.errors.txt @@ -1,35 +1,35 @@ -generatedContextualTyping.ts(219,12): error TS2870: This expression is always falsy. Did you mean to test something else? -generatedContextualTyping.ts(220,12): error TS2870: This expression is always falsy. Did you mean to test something else? -generatedContextualTyping.ts(221,12): error TS2870: This expression is always falsy. Did you mean to test something else? -generatedContextualTyping.ts(222,12): error TS2870: This expression is always falsy. Did you mean to test something else? -generatedContextualTyping.ts(223,12): error TS2870: This expression is always falsy. Did you mean to test something else? -generatedContextualTyping.ts(224,12): error TS2870: This expression is always falsy. Did you mean to test something else? -generatedContextualTyping.ts(225,12): error TS2870: This expression is always falsy. Did you mean to test something else? -generatedContextualTyping.ts(226,12): error TS2870: This expression is always falsy. Did you mean to test something else? -generatedContextualTyping.ts(259,26): error TS2869: This expression is always truthy. Did you mean to test something else? -generatedContextualTyping.ts(260,35): error TS2869: This expression is always truthy. Did you mean to test something else? -generatedContextualTyping.ts(261,29): error TS2869: This expression is always truthy. Did you mean to test something else? -generatedContextualTyping.ts(262,38): error TS2869: This expression is always truthy. Did you mean to test something else? -generatedContextualTyping.ts(263,20): error TS2869: This expression is always truthy. Did you mean to test something else? -generatedContextualTyping.ts(264,25): error TS2869: This expression is always truthy. Did you mean to test something else? -generatedContextualTyping.ts(265,36): error TS2869: This expression is always truthy. Did you mean to test something else? -generatedContextualTyping.ts(266,28): error TS2869: This expression is always truthy. Did you mean to test something else? -generatedContextualTyping.ts(267,26): error TS2870: This expression is always falsy. Did you mean to test something else? -generatedContextualTyping.ts(268,26): error TS2870: This expression is always falsy. Did you mean to test something else? -generatedContextualTyping.ts(269,29): error TS2870: This expression is always falsy. Did you mean to test something else? -generatedContextualTyping.ts(270,29): error TS2870: This expression is always falsy. Did you mean to test something else? -generatedContextualTyping.ts(271,20): error TS2870: This expression is always falsy. Did you mean to test something else? -generatedContextualTyping.ts(272,25): error TS2870: This expression is always falsy. Did you mean to test something else? -generatedContextualTyping.ts(273,36): error TS2870: This expression is always falsy. Did you mean to test something else? -generatedContextualTyping.ts(274,28): error TS2870: This expression is always falsy. Did you mean to test something else? -generatedContextualTyping.ts(275,26): error TS2869: This expression is always truthy. Did you mean to test something else? -generatedContextualTyping.ts(276,35): error TS2869: This expression is always truthy. Did you mean to test something else? -generatedContextualTyping.ts(277,29): error TS2869: This expression is always truthy. Did you mean to test something else? -generatedContextualTyping.ts(278,38): error TS2869: This expression is always truthy. Did you mean to test something else? -generatedContextualTyping.ts(279,20): error TS2869: This expression is always truthy. Did you mean to test something else? -generatedContextualTyping.ts(280,25): error TS2869: This expression is always truthy. Did you mean to test something else? -generatedContextualTyping.ts(281,36): error TS2869: This expression is always truthy. Did you mean to test something else? -generatedContextualTyping.ts(282,28): error TS2869: This expression is always truthy. Did you mean to test something else? +generatedContextualTyping.ts(219,12): error TS2873: This kind of expression is always falsy. +generatedContextualTyping.ts(220,12): error TS2873: This kind of expression is always falsy. +generatedContextualTyping.ts(221,12): error TS2873: This kind of expression is always falsy. +generatedContextualTyping.ts(222,12): error TS2873: This kind of expression is always falsy. +generatedContextualTyping.ts(223,12): error TS2873: This kind of expression is always falsy. +generatedContextualTyping.ts(224,12): error TS2873: This kind of expression is always falsy. +generatedContextualTyping.ts(225,12): error TS2873: This kind of expression is always falsy. +generatedContextualTyping.ts(226,12): error TS2873: This kind of expression is always falsy. +generatedContextualTyping.ts(259,26): error TS2872: This kind of expression is always truthy. +generatedContextualTyping.ts(260,35): error TS2872: This kind of expression is always truthy. +generatedContextualTyping.ts(261,29): error TS2872: This kind of expression is always truthy. +generatedContextualTyping.ts(262,38): error TS2872: This kind of expression is always truthy. +generatedContextualTyping.ts(263,20): error TS2872: This kind of expression is always truthy. +generatedContextualTyping.ts(264,25): error TS2872: This kind of expression is always truthy. +generatedContextualTyping.ts(265,36): error TS2872: This kind of expression is always truthy. +generatedContextualTyping.ts(266,28): error TS2872: This kind of expression is always truthy. +generatedContextualTyping.ts(267,26): error TS2873: This kind of expression is always falsy. +generatedContextualTyping.ts(268,26): error TS2873: This kind of expression is always falsy. +generatedContextualTyping.ts(269,29): error TS2873: This kind of expression is always falsy. +generatedContextualTyping.ts(270,29): error TS2873: This kind of expression is always falsy. +generatedContextualTyping.ts(271,20): error TS2873: This kind of expression is always falsy. +generatedContextualTyping.ts(272,25): error TS2873: This kind of expression is always falsy. +generatedContextualTyping.ts(273,36): error TS2873: This kind of expression is always falsy. +generatedContextualTyping.ts(274,28): error TS2873: This kind of expression is always falsy. +generatedContextualTyping.ts(275,26): error TS2872: This kind of expression is always truthy. +generatedContextualTyping.ts(276,35): error TS2872: This kind of expression is always truthy. +generatedContextualTyping.ts(277,29): error TS2872: This kind of expression is always truthy. +generatedContextualTyping.ts(278,38): error TS2872: This kind of expression is always truthy. +generatedContextualTyping.ts(279,20): error TS2872: This kind of expression is always truthy. +generatedContextualTyping.ts(280,25): error TS2872: This kind of expression is always truthy. +generatedContextualTyping.ts(281,36): error TS2872: This kind of expression is always truthy. +generatedContextualTyping.ts(282,28): error TS2872: This kind of expression is always truthy. ==== generatedContextualTyping.ts (32 errors) ==== @@ -253,28 +253,28 @@ generatedContextualTyping.ts(282,28): error TS2869: This expression is always tr var x216 = >{ func: n => { return [d1, d2]; } }; var x217 = (<() => Base[]>undefined) || function() { return [d1, d2] }; ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var x218 = (<() => Base[]>undefined) || function named() { return [d1, d2] }; ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var x219 = (<{ (): Base[]; }>undefined) || function() { return [d1, d2] }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var x220 = (<{ (): Base[]; }>undefined) || function named() { return [d1, d2] }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var x221 = (undefined) || [d1, d2]; ~~~~~~~~~~~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var x222 = (>undefined) || [d1, d2]; ~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var x223 = (<{ [n: number]: Base; }>undefined) || [d1, d2]; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var x224 = (<{n: Base[]; } >undefined) || { n: [d1, d2] }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var x225: () => Base[]; x225 = () => [d1, d2]; var x226: () => Base[]; x226 = function() { return [d1, d2] }; var x227: () => Base[]; x227 = function named() { return [d1, d2] }; @@ -309,76 +309,76 @@ generatedContextualTyping.ts(282,28): error TS2869: This expression is always tr var x260: Genric[] = [{ func: n => { return [d1, d2]; } }]; var x261: () => Base[] = function() { return [d1, d2] } || undefined; ~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var x262: () => Base[] = function named() { return [d1, d2] } || undefined; ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var x263: { (): Base[]; } = function() { return [d1, d2] } || undefined; ~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var x264: { (): Base[]; } = function named() { return [d1, d2] } || undefined; ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var x265: Base[] = [d1, d2] || undefined; ~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var x266: Array = [d1, d2] || undefined; ~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var x267: { [n: number]: Base; } = [d1, d2] || undefined; ~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var x268: {n: Base[]; } = { n: [d1, d2] } || undefined; ~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var x269: () => Base[] = undefined || function() { return [d1, d2] }; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var x270: () => Base[] = undefined || function named() { return [d1, d2] }; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var x271: { (): Base[]; } = undefined || function() { return [d1, d2] }; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var x272: { (): Base[]; } = undefined || function named() { return [d1, d2] }; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var x273: Base[] = undefined || [d1, d2]; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var x274: Array = undefined || [d1, d2]; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var x275: { [n: number]: Base; } = undefined || [d1, d2]; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var x276: {n: Base[]; } = undefined || { n: [d1, d2] }; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var x277: () => Base[] = function() { return [d1, d2] } || function() { return [d1, d2] }; ~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var x278: () => Base[] = function named() { return [d1, d2] } || function named() { return [d1, d2] }; ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var x279: { (): Base[]; } = function() { return [d1, d2] } || function() { return [d1, d2] }; ~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var x280: { (): Base[]; } = function named() { return [d1, d2] } || function named() { return [d1, d2] }; ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var x281: Base[] = [d1, d2] || [d1, d2]; ~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var x282: Array = [d1, d2] || [d1, d2]; ~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var x283: { [n: number]: Base; } = [d1, d2] || [d1, d2]; ~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var x284: {n: Base[]; } = { n: [d1, d2] } || { n: [d1, d2] }; ~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var x285: () => Base[] = true ? () => [d1, d2] : () => [d1, d2]; var x286: () => Base[] = true ? function() { return [d1, d2] } : function() { return [d1, d2] }; var x287: () => Base[] = true ? function named() { return [d1, d2] } : function named() { return [d1, d2] }; diff --git a/tests/baselines/reference/ifDoWhileStatements.errors.txt b/tests/baselines/reference/ifDoWhileStatements.errors.txt index d0f9d226df311..bbeaa9db15df4 100644 --- a/tests/baselines/reference/ifDoWhileStatements.errors.txt +++ b/tests/baselines/reference/ifDoWhileStatements.errors.txt @@ -1,30 +1,30 @@ -ifDoWhileStatements.ts(48,5): error TS2870: This expression is always falsy. Did you mean to test something else? -ifDoWhileStatements.ts(49,8): error TS2870: This expression is always falsy. Did you mean to test something else? -ifDoWhileStatements.ts(50,13): error TS2870: This expression is always falsy. Did you mean to test something else? -ifDoWhileStatements.ts(56,5): error TS2869: This expression is always truthy. Did you mean to test something else? -ifDoWhileStatements.ts(57,8): error TS2869: This expression is always truthy. Did you mean to test something else? -ifDoWhileStatements.ts(58,13): error TS2869: This expression is always truthy. Did you mean to test something else? -ifDoWhileStatements.ts(60,5): error TS2870: This expression is always falsy. Did you mean to test something else? -ifDoWhileStatements.ts(61,8): error TS2870: This expression is always falsy. Did you mean to test something else? -ifDoWhileStatements.ts(62,13): error TS2870: This expression is always falsy. Did you mean to test something else? -ifDoWhileStatements.ts(64,5): error TS2869: This expression is always truthy. Did you mean to test something else? -ifDoWhileStatements.ts(65,8): error TS2869: This expression is always truthy. Did you mean to test something else? -ifDoWhileStatements.ts(66,13): error TS2869: This expression is always truthy. Did you mean to test something else? -ifDoWhileStatements.ts(68,5): error TS2869: This expression is always truthy. Did you mean to test something else? -ifDoWhileStatements.ts(69,8): error TS2869: This expression is always truthy. Did you mean to test something else? -ifDoWhileStatements.ts(70,13): error TS2869: This expression is always truthy. Did you mean to test something else? -ifDoWhileStatements.ts(72,5): error TS2869: This expression is always truthy. Did you mean to test something else? -ifDoWhileStatements.ts(73,8): error TS2869: This expression is always truthy. Did you mean to test something else? -ifDoWhileStatements.ts(74,13): error TS2869: This expression is always truthy. Did you mean to test something else? -ifDoWhileStatements.ts(76,5): error TS2869: This expression is always truthy. Did you mean to test something else? -ifDoWhileStatements.ts(77,8): error TS2869: This expression is always truthy. Did you mean to test something else? -ifDoWhileStatements.ts(78,13): error TS2869: This expression is always truthy. Did you mean to test something else? -ifDoWhileStatements.ts(80,5): error TS2869: This expression is always truthy. Did you mean to test something else? -ifDoWhileStatements.ts(81,8): error TS2869: This expression is always truthy. Did you mean to test something else? -ifDoWhileStatements.ts(82,13): error TS2869: This expression is always truthy. Did you mean to test something else? -ifDoWhileStatements.ts(84,5): error TS2869: This expression is always truthy. Did you mean to test something else? -ifDoWhileStatements.ts(85,8): error TS2869: This expression is always truthy. Did you mean to test something else? -ifDoWhileStatements.ts(86,13): error TS2869: This expression is always truthy. Did you mean to test something else? +ifDoWhileStatements.ts(48,5): error TS2873: This kind of expression is always falsy. +ifDoWhileStatements.ts(49,8): error TS2873: This kind of expression is always falsy. +ifDoWhileStatements.ts(50,13): error TS2873: This kind of expression is always falsy. +ifDoWhileStatements.ts(56,5): error TS2872: This kind of expression is always truthy. +ifDoWhileStatements.ts(57,8): error TS2872: This kind of expression is always truthy. +ifDoWhileStatements.ts(58,13): error TS2872: This kind of expression is always truthy. +ifDoWhileStatements.ts(60,5): error TS2873: This kind of expression is always falsy. +ifDoWhileStatements.ts(61,8): error TS2873: This kind of expression is always falsy. +ifDoWhileStatements.ts(62,13): error TS2873: This kind of expression is always falsy. +ifDoWhileStatements.ts(64,5): error TS2872: This kind of expression is always truthy. +ifDoWhileStatements.ts(65,8): error TS2872: This kind of expression is always truthy. +ifDoWhileStatements.ts(66,13): error TS2872: This kind of expression is always truthy. +ifDoWhileStatements.ts(68,5): error TS2872: This kind of expression is always truthy. +ifDoWhileStatements.ts(69,8): error TS2872: This kind of expression is always truthy. +ifDoWhileStatements.ts(70,13): error TS2872: This kind of expression is always truthy. +ifDoWhileStatements.ts(72,5): error TS2872: This kind of expression is always truthy. +ifDoWhileStatements.ts(73,8): error TS2872: This kind of expression is always truthy. +ifDoWhileStatements.ts(74,13): error TS2872: This kind of expression is always truthy. +ifDoWhileStatements.ts(76,5): error TS2872: This kind of expression is always truthy. +ifDoWhileStatements.ts(77,8): error TS2872: This kind of expression is always truthy. +ifDoWhileStatements.ts(78,13): error TS2872: This kind of expression is always truthy. +ifDoWhileStatements.ts(80,5): error TS2872: This kind of expression is always truthy. +ifDoWhileStatements.ts(81,8): error TS2872: This kind of expression is always truthy. +ifDoWhileStatements.ts(82,13): error TS2872: This kind of expression is always truthy. +ifDoWhileStatements.ts(84,5): error TS2872: This kind of expression is always truthy. +ifDoWhileStatements.ts(85,8): error TS2872: This kind of expression is always truthy. +ifDoWhileStatements.ts(86,13): error TS2872: This kind of expression is always truthy. ==== ifDoWhileStatements.ts (27 errors) ==== @@ -77,13 +77,13 @@ ifDoWhileStatements.ts(86,13): error TS2869: This expression is always truthy. D if (undefined) { } ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. while (undefined) { } ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. do { }while(undefined) ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. if (0.0) { } while (0.0) { } @@ -91,83 +91,83 @@ ifDoWhileStatements.ts(86,13): error TS2869: This expression is always truthy. D if ('a string') { } ~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. while ('a string') { } ~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. do { }while('a string') ~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. if ('') { } ~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. while ('') { } ~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. do { }while('') ~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. if (/[a-z]/) { } ~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. while (/[a-z]/) { } ~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. do { }while(/[a-z]/) ~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. if ([]) { } ~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. while ([]) { } ~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. do { }while([]) ~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. if ([1, 2]) { } ~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. while ([1, 2]) { } ~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. do { }while([1, 2]) ~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. if ({}) { } ~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. while ({}) { } ~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. do { }while({}) ~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. if ({ x: 1, y: 'a' }) { } ~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. while ({ x: 1, y: 'a' }) { } ~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. do { }while({ x: 1, y: 'a' }) ~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. if (() => 43) { } ~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. while (() => 43) { } ~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. do { }while(() => 43) ~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. if (new C()) { } while (new C()) { } diff --git a/tests/baselines/reference/initializersWidened.errors.txt b/tests/baselines/reference/initializersWidened.errors.txt index c076ca15b57a8..28a8315a1906e 100644 --- a/tests/baselines/reference/initializersWidened.errors.txt +++ b/tests/baselines/reference/initializersWidened.errors.txt @@ -1,7 +1,7 @@ -initializersWidened.ts(19,10): error TS2870: This expression is always falsy. Did you mean to test something else? -initializersWidened.ts(20,10): error TS2870: This expression is always falsy. Did you mean to test something else? -initializersWidened.ts(23,10): error TS2870: This expression is always falsy. Did you mean to test something else? -initializersWidened.ts(24,10): error TS2870: This expression is always falsy. Did you mean to test something else? +initializersWidened.ts(19,10): error TS2873: This kind of expression is always falsy. +initializersWidened.ts(20,10): error TS2873: This kind of expression is always falsy. +initializersWidened.ts(23,10): error TS2873: This kind of expression is always falsy. +initializersWidened.ts(24,10): error TS2873: This kind of expression is always falsy. ==== initializersWidened.ts (4 errors) ==== @@ -25,15 +25,15 @@ initializersWidened.ts(24,10): error TS2870: This expression is always falsy. Di var x4 = null || null; var y4 = undefined || undefined; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var z4 = void 0 || void 0; ~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var x5 = null || x2; var y5 = undefined || y2; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var z5 = void 0 || y2; ~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? \ No newline at end of file +!!! error TS2873: This kind of expression is always falsy. \ No newline at end of file diff --git a/tests/baselines/reference/logicalAndOperatorWithEveryType.errors.txt b/tests/baselines/reference/logicalAndOperatorWithEveryType.errors.txt index 24834f4d9f40b..5ef762173ea3d 100644 --- a/tests/baselines/reference/logicalAndOperatorWithEveryType.errors.txt +++ b/tests/baselines/reference/logicalAndOperatorWithEveryType.errors.txt @@ -1,23 +1,23 @@ logicalAndOperatorWithEveryType.ts(19,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. -logicalAndOperatorWithEveryType.ts(24,12): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalAndOperatorWithEveryType.ts(24,12): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(30,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. -logicalAndOperatorWithEveryType.ts(35,12): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalAndOperatorWithEveryType.ts(35,12): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(41,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. -logicalAndOperatorWithEveryType.ts(46,12): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalAndOperatorWithEveryType.ts(46,12): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(52,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. -logicalAndOperatorWithEveryType.ts(57,12): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalAndOperatorWithEveryType.ts(57,12): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(63,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. -logicalAndOperatorWithEveryType.ts(68,12): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalAndOperatorWithEveryType.ts(68,12): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(74,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. -logicalAndOperatorWithEveryType.ts(79,12): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalAndOperatorWithEveryType.ts(79,12): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(85,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. -logicalAndOperatorWithEveryType.ts(90,12): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalAndOperatorWithEveryType.ts(90,12): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(96,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. -logicalAndOperatorWithEveryType.ts(101,12): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalAndOperatorWithEveryType.ts(101,12): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(107,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. -logicalAndOperatorWithEveryType.ts(112,12): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalAndOperatorWithEveryType.ts(112,12): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(118,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. -logicalAndOperatorWithEveryType.ts(123,12): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalAndOperatorWithEveryType.ts(123,12): error TS2873: This kind of expression is always falsy. ==== logicalAndOperatorWithEveryType.ts (20 errors) ==== @@ -48,7 +48,7 @@ logicalAndOperatorWithEveryType.ts(123,12): error TS2870: This expression is alw var ra9 = null && a1; var ra10 = undefined && a1; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var rb1 = a1 && a2; var rb2 = a2 && a2; @@ -63,7 +63,7 @@ logicalAndOperatorWithEveryType.ts(123,12): error TS2870: This expression is alw var rb9 = null && a2; var rb10 = undefined && a2; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var rc1 = a1 && a3; var rc2 = a2 && a3; @@ -78,7 +78,7 @@ logicalAndOperatorWithEveryType.ts(123,12): error TS2870: This expression is alw var rc9 = null && a3; var rc10 = undefined && a3; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var rd1 = a1 && a4; var rd2 = a2 && a4; @@ -93,7 +93,7 @@ logicalAndOperatorWithEveryType.ts(123,12): error TS2870: This expression is alw var rd9 = null && a4; var rd10 = undefined && a4; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var re1 = a1 && a5; var re2 = a2 && a5; @@ -108,7 +108,7 @@ logicalAndOperatorWithEveryType.ts(123,12): error TS2870: This expression is alw var re9 = null && a5; var re10 = undefined && a5; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var rf1 = a1 && a6; var rf2 = a2 && a6; @@ -123,7 +123,7 @@ logicalAndOperatorWithEveryType.ts(123,12): error TS2870: This expression is alw var rf9 = null && a6; var rf10 = undefined && a6; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var rg1 = a1 && a7; var rg2 = a2 && a7; @@ -138,7 +138,7 @@ logicalAndOperatorWithEveryType.ts(123,12): error TS2870: This expression is alw var rg9 = null && a7; var rg10 = undefined && a7; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var rh1 = a1 && a8; var rh2 = a2 && a8; @@ -153,7 +153,7 @@ logicalAndOperatorWithEveryType.ts(123,12): error TS2870: This expression is alw var rh9 = null && a8; var rh10 = undefined && a8; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var ri1 = a1 && null; var ri2 = a2 && null; @@ -168,7 +168,7 @@ logicalAndOperatorWithEveryType.ts(123,12): error TS2870: This expression is alw var ri9 = null && null; var ri10 = undefined && null; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var rj1 = a1 && undefined; var rj2 = a2 && undefined; @@ -183,4 +183,4 @@ logicalAndOperatorWithEveryType.ts(123,12): error TS2870: This expression is alw var rj9 = null && undefined; var rj10 = undefined && undefined; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? \ No newline at end of file +!!! error TS2873: This kind of expression is always falsy. \ No newline at end of file diff --git a/tests/baselines/reference/logicalNotOperatorWithAnyOtherType.errors.txt b/tests/baselines/reference/logicalNotOperatorWithAnyOtherType.errors.txt index 49503ec38dfcd..09d91a27d6009 100644 --- a/tests/baselines/reference/logicalNotOperatorWithAnyOtherType.errors.txt +++ b/tests/baselines/reference/logicalNotOperatorWithAnyOtherType.errors.txt @@ -1,4 +1,4 @@ -logicalNotOperatorWithAnyOtherType.ts(33,25): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalNotOperatorWithAnyOtherType.ts(33,25): error TS2873: This kind of expression is always falsy. logicalNotOperatorWithAnyOtherType.ts(45,27): error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. logicalNotOperatorWithAnyOtherType.ts(46,27): error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. logicalNotOperatorWithAnyOtherType.ts(47,27): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. @@ -40,7 +40,7 @@ logicalNotOperatorWithAnyOtherType.ts(57,1): error TS2695: Left side of comma op // any type literal var ResultIsBoolean7 = !undefined; ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var ResultIsBoolean8 = !null; // any type expressions diff --git a/tests/baselines/reference/logicalNotOperatorWithBooleanType.errors.txt b/tests/baselines/reference/logicalNotOperatorWithBooleanType.errors.txt index 2feb09506c396..981e44fe46d48 100644 --- a/tests/baselines/reference/logicalNotOperatorWithBooleanType.errors.txt +++ b/tests/baselines/reference/logicalNotOperatorWithBooleanType.errors.txt @@ -1,4 +1,4 @@ -logicalNotOperatorWithBooleanType.ts(21,25): error TS2869: This expression is always truthy. Did you mean to test something else? +logicalNotOperatorWithBooleanType.ts(21,25): error TS2872: This kind of expression is always truthy. logicalNotOperatorWithBooleanType.ts(36,1): error TS2695: Left side of comma operator is unused and has no side effects. @@ -25,7 +25,7 @@ logicalNotOperatorWithBooleanType.ts(36,1): error TS2695: Left side of comma ope var ResultIsBoolean2 = !true; var ResultIsBoolean3 = !{ x: true, y: false }; ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. // boolean type expressions var ResultIsBoolean4 = !objA.a; diff --git a/tests/baselines/reference/logicalNotOperatorWithNumberType.errors.txt b/tests/baselines/reference/logicalNotOperatorWithNumberType.errors.txt index cd854fcd77cb6..03ced35d64485 100644 --- a/tests/baselines/reference/logicalNotOperatorWithNumberType.errors.txt +++ b/tests/baselines/reference/logicalNotOperatorWithNumberType.errors.txt @@ -1,5 +1,5 @@ -logicalNotOperatorWithNumberType.ts(23,25): error TS2869: This expression is always truthy. Did you mean to test something else? -logicalNotOperatorWithNumberType.ts(24,25): error TS2869: This expression is always truthy. Did you mean to test something else? +logicalNotOperatorWithNumberType.ts(23,25): error TS2872: This kind of expression is always truthy. +logicalNotOperatorWithNumberType.ts(24,25): error TS2872: This kind of expression is always truthy. logicalNotOperatorWithNumberType.ts(45,1): error TS2695: Left side of comma operator is unused and has no side effects. @@ -28,10 +28,10 @@ logicalNotOperatorWithNumberType.ts(45,1): error TS2695: Left side of comma oper var ResultIsBoolean3 = !1; var ResultIsBoolean4 = !{ x: 1, y: 2}; ~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var ResultIsBoolean5 = !{ x: 1, y: (n: number) => { return n; } }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. // number type expressions var ResultIsBoolean6 = !objA.a; diff --git a/tests/baselines/reference/logicalNotOperatorWithStringType.errors.txt b/tests/baselines/reference/logicalNotOperatorWithStringType.errors.txt index 77f74d0561537..6ea2e395e8038 100644 --- a/tests/baselines/reference/logicalNotOperatorWithStringType.errors.txt +++ b/tests/baselines/reference/logicalNotOperatorWithStringType.errors.txt @@ -1,7 +1,7 @@ -logicalNotOperatorWithStringType.ts(22,25): error TS2870: This expression is always falsy. Did you mean to test something else? -logicalNotOperatorWithStringType.ts(23,25): error TS2869: This expression is always truthy. Did you mean to test something else? -logicalNotOperatorWithStringType.ts(24,25): error TS2869: This expression is always truthy. Did you mean to test something else? -logicalNotOperatorWithStringType.ts(40,2): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalNotOperatorWithStringType.ts(22,25): error TS2873: This kind of expression is always falsy. +logicalNotOperatorWithStringType.ts(23,25): error TS2872: This kind of expression is always truthy. +logicalNotOperatorWithStringType.ts(24,25): error TS2872: This kind of expression is always truthy. +logicalNotOperatorWithStringType.ts(40,2): error TS2873: This kind of expression is always falsy. logicalNotOperatorWithStringType.ts(44,1): error TS2695: Left side of comma operator is unused and has no side effects. @@ -29,13 +29,13 @@ logicalNotOperatorWithStringType.ts(44,1): error TS2695: Left side of comma oper // string type literal var ResultIsBoolean3 = !""; ~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var ResultIsBoolean4 = !{ x: "", y: "" }; ~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. var ResultIsBoolean5 = !{ x: "", y: (s: string) => { return s; } }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. // string type expressions var ResultIsBoolean6 = !objA.a; @@ -53,7 +53,7 @@ logicalNotOperatorWithStringType.ts(44,1): error TS2695: Left side of comma oper // miss assignment operators !""; ~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. !STRING; !STRING1; !foo(); diff --git a/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.errors.txt b/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.errors.txt index 94c9265e6c098..46043459485b9 100644 --- a/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.errors.txt +++ b/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.errors.txt @@ -1,4 +1,4 @@ -logicalOrExpressionIsContextuallyTyped.ts(6,24): error TS2869: This expression is always truthy. Did you mean to test something else? +logicalOrExpressionIsContextuallyTyped.ts(6,24): error TS2872: This kind of expression is always truthy. logicalOrExpressionIsContextuallyTyped.ts(6,33): error TS2322: Type '{ a: string; b: number; } | { a: string; b: boolean; }' is not assignable to type '{ a: string; }'. Object literal may only specify known properties, and 'b' does not exist in type '{ a: string; }'. @@ -11,7 +11,7 @@ logicalOrExpressionIsContextuallyTyped.ts(6,33): error TS2322: Type '{ a: string var r: { a: string } = { a: '', b: 123 } || { a: '', b: true }; ~~~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. ~ !!! error TS2322: Type '{ a: string; b: number; } | { a: string; b: boolean; }' is not assignable to type '{ a: string; }'. !!! error TS2322: Object literal may only specify known properties, and 'b' does not exist in type '{ a: string; }'. \ No newline at end of file diff --git a/tests/baselines/reference/logicalOrOperatorWithEveryType.errors.txt b/tests/baselines/reference/logicalOrOperatorWithEveryType.errors.txt index 0c2a0e96ea09b..84d06759e4b80 100644 --- a/tests/baselines/reference/logicalOrOperatorWithEveryType.errors.txt +++ b/tests/baselines/reference/logicalOrOperatorWithEveryType.errors.txt @@ -1,23 +1,23 @@ logicalOrOperatorWithEveryType.ts(21,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. -logicalOrOperatorWithEveryType.ts(26,12): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalOrOperatorWithEveryType.ts(26,12): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(32,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. -logicalOrOperatorWithEveryType.ts(37,11): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalOrOperatorWithEveryType.ts(37,11): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(43,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. -logicalOrOperatorWithEveryType.ts(48,12): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalOrOperatorWithEveryType.ts(48,12): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(54,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. -logicalOrOperatorWithEveryType.ts(59,12): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalOrOperatorWithEveryType.ts(59,12): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(65,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. -logicalOrOperatorWithEveryType.ts(70,12): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalOrOperatorWithEveryType.ts(70,12): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(76,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. -logicalOrOperatorWithEveryType.ts(81,12): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalOrOperatorWithEveryType.ts(81,12): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(87,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. -logicalOrOperatorWithEveryType.ts(92,12): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalOrOperatorWithEveryType.ts(92,12): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(98,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. -logicalOrOperatorWithEveryType.ts(103,12): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalOrOperatorWithEveryType.ts(103,12): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(109,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. -logicalOrOperatorWithEveryType.ts(114,12): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalOrOperatorWithEveryType.ts(114,12): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(120,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. -logicalOrOperatorWithEveryType.ts(125,12): error TS2870: This expression is always falsy. Did you mean to test something else? +logicalOrOperatorWithEveryType.ts(125,12): error TS2873: This kind of expression is always falsy. ==== logicalOrOperatorWithEveryType.ts (20 errors) ==== @@ -50,7 +50,7 @@ logicalOrOperatorWithEveryType.ts(125,12): error TS2870: This expression is alwa var ra9 = null || a1; // null || any is any var ra10 = undefined || a1; // undefined || any is any ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var rb1 = a1 || a2; // any || boolean is any var rb2 = a2 || a2; // boolean || boolean is boolean @@ -65,7 +65,7 @@ logicalOrOperatorWithEveryType.ts(125,12): error TS2870: This expression is alwa var rb9 = null || a2; // null || boolean is boolean var rb10= undefined || a2; // undefined || boolean is boolean ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var rc1 = a1 || a3; // any || number is any var rc2 = a2 || a3; // boolean || number is boolean | number @@ -80,7 +80,7 @@ logicalOrOperatorWithEveryType.ts(125,12): error TS2870: This expression is alwa var rc9 = null || a3; // null || number is number var rc10 = undefined || a3; // undefined || number is number ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var rd1 = a1 || a4; // any || string is any var rd2 = a2 || a4; // boolean || string is boolean | string @@ -95,7 +95,7 @@ logicalOrOperatorWithEveryType.ts(125,12): error TS2870: This expression is alwa var rd9 = null || a4; // null || string is string var rd10 = undefined || a4; // undefined || string is string ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var re1 = a1 || a5; // any || void is any var re2 = a2 || a5; // boolean || void is boolean | void @@ -110,7 +110,7 @@ logicalOrOperatorWithEveryType.ts(125,12): error TS2870: This expression is alwa var re9 = null || a5; // null || void is void var re10 = undefined || a5; // undefined || void is void ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var rg1 = a1 || a6; // any || enum is any var rg2 = a2 || a6; // boolean || enum is boolean | enum @@ -125,7 +125,7 @@ logicalOrOperatorWithEveryType.ts(125,12): error TS2870: This expression is alwa var rg9 = null || a6; // null || enum is E var rg10 = undefined || a6; // undefined || enum is E ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var rh1 = a1 || a7; // any || object is any var rh2 = a2 || a7; // boolean || object is boolean | object @@ -140,7 +140,7 @@ logicalOrOperatorWithEveryType.ts(125,12): error TS2870: This expression is alwa var rh9 = null || a7; // null || object is object var rh10 = undefined || a7; // undefined || object is object ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var ri1 = a1 || a8; // any || array is any var ri2 = a2 || a8; // boolean || array is boolean | array @@ -155,7 +155,7 @@ logicalOrOperatorWithEveryType.ts(125,12): error TS2870: This expression is alwa var ri9 = null || a8; // null || array is array var ri10 = undefined || a8; // undefined || array is array ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var rj1 = a1 || null; // any || null is any var rj2 = a2 || null; // boolean || null is boolean @@ -170,7 +170,7 @@ logicalOrOperatorWithEveryType.ts(125,12): error TS2870: This expression is alwa var rj9 = null || null; // null || null is any var rj10 = undefined || null; // undefined || null is any ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var rf1 = a1 || undefined; // any || undefined is any var rf2 = a2 || undefined; // boolean || undefined is boolean @@ -185,4 +185,4 @@ logicalOrOperatorWithEveryType.ts(125,12): error TS2870: This expression is alwa var rf9 = null || undefined; // null || undefined is any var rf10 = undefined || undefined; // undefined || undefined is any ~~~~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? \ No newline at end of file +!!! error TS2873: This kind of expression is always falsy. \ No newline at end of file diff --git a/tests/baselines/reference/nestedIfStatement.errors.txt b/tests/baselines/reference/nestedIfStatement.errors.txt index 13eddc2e8334c..3f79ac323fe68 100644 --- a/tests/baselines/reference/nestedIfStatement.errors.txt +++ b/tests/baselines/reference/nestedIfStatement.errors.txt @@ -1,5 +1,5 @@ -nestedIfStatement.ts(3,12): error TS2869: This expression is always truthy. Did you mean to test something else? -nestedIfStatement.ts(4,12): error TS2869: This expression is always truthy. Did you mean to test something else? +nestedIfStatement.ts(3,12): error TS2872: This kind of expression is always truthy. +nestedIfStatement.ts(4,12): error TS2872: This kind of expression is always truthy. ==== nestedIfStatement.ts (2 errors) ==== @@ -7,9 +7,9 @@ nestedIfStatement.ts(4,12): error TS2869: This expression is always truthy. Did } else if (1) { } else if (2) { ~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. } else if (3) { ~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. } else { } \ No newline at end of file diff --git a/tests/baselines/reference/noImplicitAnyForIn.errors.txt b/tests/baselines/reference/noImplicitAnyForIn.errors.txt index d4cf8de1e3f57..5ad0d6231fbfd 100644 --- a/tests/baselines/reference/noImplicitAnyForIn.errors.txt +++ b/tests/baselines/reference/noImplicitAnyForIn.errors.txt @@ -3,7 +3,7 @@ noImplicitAnyForIn.ts(7,18): error TS7053: Element implicitly has an 'any' type noImplicitAnyForIn.ts(14,18): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'. No index signature with a parameter of type 'string' was found on type '{}'. noImplicitAnyForIn.ts(28,5): error TS7005: Variable 'n' implicitly has an 'any[][]' type. -noImplicitAnyForIn.ts(28,9): error TS2869: This expression is always truthy. Did you mean to test something else? +noImplicitAnyForIn.ts(28,9): error TS2872: This kind of expression is always truthy. noImplicitAnyForIn.ts(30,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. @@ -45,7 +45,7 @@ noImplicitAnyForIn.ts(30,6): error TS2405: The left-hand side of a 'for...in' st ~ !!! error TS7005: Variable 'n' implicitly has an 'any[][]' type. ~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. for (n[idx++] in m); ~~~~~~~~ diff --git a/tests/baselines/reference/nullishCoalescingOperator1.errors.txt b/tests/baselines/reference/nullishCoalescingOperator1.errors.txt index c14b4fe0b3b34..951ed048b8913 100644 --- a/tests/baselines/reference/nullishCoalescingOperator1.errors.txt +++ b/tests/baselines/reference/nullishCoalescingOperator1.errors.txt @@ -1,4 +1,4 @@ -nullishCoalescingOperator1.ts(59,5): error TS2871: Using ?? on this expression appears unintentional because it always evaluates to the same nullishness. +nullishCoalescingOperator1.ts(59,5): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. ==== nullishCoalescingOperator1.ts (1 errors) ==== @@ -62,7 +62,7 @@ nullishCoalescingOperator1.ts(59,5): error TS2871: Using ?? on this expression a if (false ?? true) { ~~~~~ -!!! error TS2871: Using ?? on this expression appears unintentional because it always evaluates to the same nullishness. +!!! error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. foo(); } else { diff --git a/tests/baselines/reference/nullishCoalescingOperator7.errors.txt b/tests/baselines/reference/nullishCoalescingOperator7.errors.txt index 295b9590be99c..008d589a9e769 100644 --- a/tests/baselines/reference/nullishCoalescingOperator7.errors.txt +++ b/tests/baselines/reference/nullishCoalescingOperator7.errors.txt @@ -1,6 +1,6 @@ -nullishCoalescingOperator7.ts(6,19): error TS2869: This expression is always truthy. Did you mean to test something else? -nullishCoalescingOperator7.ts(7,19): error TS2869: This expression is always truthy. Did you mean to test something else? -nullishCoalescingOperator7.ts(10,23): error TS2869: This expression is always truthy. Did you mean to test something else? +nullishCoalescingOperator7.ts(6,19): error TS2872: This kind of expression is always truthy. +nullishCoalescingOperator7.ts(7,19): error TS2872: This kind of expression is always truthy. +nullishCoalescingOperator7.ts(10,23): error TS2872: This kind of expression is always truthy. ==== nullishCoalescingOperator7.ts (3 errors) ==== @@ -11,14 +11,14 @@ nullishCoalescingOperator7.ts(10,23): error TS2869: This expression is always tr const foo1 = a ? 1 : 2; const foo2 = a ?? 'foo' ? 1 : 2; ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. const foo3 = a ?? 'foo' ? (b ?? 'bar') : (c ?? 'baz'); ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. function f () { const foo4 = a ?? 'foo' ? b ?? 'bar' : c ?? 'baz'; ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. } \ No newline at end of file diff --git a/tests/baselines/reference/parserArrowFunctionExpression3.errors.txt b/tests/baselines/reference/parserArrowFunctionExpression3.errors.txt index 400ae09f18799..608d562872a9e 100644 --- a/tests/baselines/reference/parserArrowFunctionExpression3.errors.txt +++ b/tests/baselines/reference/parserArrowFunctionExpression3.errors.txt @@ -1,5 +1,5 @@ parserArrowFunctionExpression3.ts(1,1): error TS2304: Cannot find name 'a'. -parserArrowFunctionExpression3.ts(1,5): error TS2869: This expression is always truthy. Did you mean to test something else? +parserArrowFunctionExpression3.ts(1,5): error TS2872: This kind of expression is always truthy. parserArrowFunctionExpression3.ts(1,16): error TS1005: ')' expected. parserArrowFunctionExpression3.ts(1,19): error TS2304: Cannot find name 'a'. parserArrowFunctionExpression3.ts(1,20): error TS1005: ';' expected. @@ -10,7 +10,7 @@ parserArrowFunctionExpression3.ts(1,20): error TS1005: ';' expected. ~ !!! error TS2304: Cannot find name 'a'. ~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. ~~ !!! error TS1005: ')' expected. ~ diff --git a/tests/baselines/reference/parserRegularExpression3.errors.txt b/tests/baselines/reference/parserRegularExpression3.errors.txt index 2f842db1ef1b2..a6fc2be7ea7cb 100644 --- a/tests/baselines/reference/parserRegularExpression3.errors.txt +++ b/tests/baselines/reference/parserRegularExpression3.errors.txt @@ -1,5 +1,5 @@ parserRegularExpression3.ts(1,1): error TS2304: Cannot find name 'Foo'. -parserRegularExpression3.ts(1,6): error TS2869: This expression is always truthy. Did you mean to test something else? +parserRegularExpression3.ts(1,6): error TS2872: This kind of expression is always truthy. ==== parserRegularExpression3.ts (2 errors) ==== @@ -7,4 +7,4 @@ parserRegularExpression3.ts(1,6): error TS2869: This expression is always truthy ~~~ !!! error TS2304: Cannot find name 'Foo'. ~~~~~~~~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? \ No newline at end of file +!!! error TS2872: This kind of expression is always truthy. \ No newline at end of file diff --git a/tests/baselines/reference/predicateSemantics.errors.txt b/tests/baselines/reference/predicateSemantics.errors.txt index 22ae815b5e613..a02d2009f1b0b 100644 --- a/tests/baselines/reference/predicateSemantics.errors.txt +++ b/tests/baselines/reference/predicateSemantics.errors.txt @@ -1,8 +1,13 @@ -predicateSemantics.ts(7,16): error TS2871: Using ?? on this expression appears unintentional because it always evaluates to the same nullishness. -predicateSemantics.ts(10,16): error TS2871: Using ?? on this expression appears unintentional because it always evaluates to the same nullishness. +predicateSemantics.ts(7,16): error TS2871: This expression is always nullish. +predicateSemantics.ts(10,16): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. +predicateSemantics.ts(26,12): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. +predicateSemantics.ts(27,12): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. +predicateSemantics.ts(28,12): error TS2871: This expression is always nullish. +predicateSemantics.ts(29,12): error TS2872: This kind of expression is always truthy. +predicateSemantics.ts(30,12): error TS2872: This kind of expression is always truthy. -==== predicateSemantics.ts (2 errors) ==== +==== predicateSemantics.ts (7 errors) ==== declare let cond: any; // OK: One or other operand is possibly nullish @@ -11,12 +16,12 @@ predicateSemantics.ts(10,16): error TS2871: Using ?? on this expression appears // Not OK: Both operands nullish const test2 = (cond ? undefined : null) ?? "always reached"; ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2871: Using ?? on this expression appears unintentional because it always evaluates to the same nullishness. +!!! error TS2871: This expression is always nullish. // Not OK: Both operands non-nullish const test3 = (cond ? 132 : 17) ?? "unreachable"; ~~~~~~~~~~~~~~~ -!!! error TS2871: Using ?? on this expression appears unintentional because it always evaluates to the same nullishness. +!!! error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. // Parens const test4 = (cond ? (undefined) : (17)) ?? 42; @@ -26,4 +31,25 @@ predicateSemantics.ts(10,16): error TS2871: Using ?? on this expression appears } + // Should be OK (special cases) + while (0) { } + while (1) { } + while (true) { } + while (false) { } + + const p5 = {} ?? null; + ~~ +!!! error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. + const p6 = 0 > 1 ?? null; + ~~~~~ +!!! error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. + const p7 = null ?? null; + ~~~~ +!!! error TS2871: This expression is always nullish. + const p8 = (class foo { }) && null; + ~~~~~~~~~~~~~~~ +!!! error TS2872: This kind of expression is always truthy. + const p9 = (class foo { }) || null; + ~~~~~~~~~~~~~~~ +!!! error TS2872: This kind of expression is always truthy. \ No newline at end of file diff --git a/tests/baselines/reference/predicateSemantics.js b/tests/baselines/reference/predicateSemantics.js index 24f8f0a716640..0df3aea915e35 100644 --- a/tests/baselines/reference/predicateSemantics.js +++ b/tests/baselines/reference/predicateSemantics.js @@ -20,10 +20,21 @@ if (!!true) { } +// Should be OK (special cases) +while (0) { } +while (1) { } +while (true) { } +while (false) { } + +const p5 = {} ?? null; +const p6 = 0 > 1 ?? null; +const p7 = null ?? null; +const p8 = (class foo { }) && null; +const p9 = (class foo { }) || null; //// [predicateSemantics.js] -var _a, _b, _c, _d; +var _a, _b, _c, _d, _e, _f; // OK: One or other operand is possibly nullish var test1 = (_a = (cond ? undefined : 32)) !== null && _a !== void 0 ? _a : "possibly reached"; // Not OK: Both operands nullish @@ -35,3 +46,21 @@ var test4 = (_d = (cond ? (undefined) : (17))) !== null && _d !== void 0 ? _d : // Should be OK (special case) if (!!true) { } +// Should be OK (special cases) +while (0) { } +while (1) { } +while (true) { } +while (false) { } +var p5 = (_e = {}) !== null && _e !== void 0 ? _e : null; +var p6 = (_f = 0 > 1) !== null && _f !== void 0 ? _f : null; +var p7 = null !== null && null !== void 0 ? null : null; +var p8 = (/** @class */ (function () { + function foo() { + } + return foo; +}())) && null; +var p9 = (/** @class */ (function () { + function foo() { + } + return foo; +}())) || null; diff --git a/tests/baselines/reference/predicateSemantics.symbols b/tests/baselines/reference/predicateSemantics.symbols index a20a75a9cea81..6881f89f06381 100644 --- a/tests/baselines/reference/predicateSemantics.symbols +++ b/tests/baselines/reference/predicateSemantics.symbols @@ -32,4 +32,26 @@ if (!!true) { } +// Should be OK (special cases) +while (0) { } +while (1) { } +while (true) { } +while (false) { } + +const p5 = {} ?? null; +>p5 : Symbol(p5, Decl(predicateSemantics.ts, 25, 5)) + +const p6 = 0 > 1 ?? null; +>p6 : Symbol(p6, Decl(predicateSemantics.ts, 26, 5)) + +const p7 = null ?? null; +>p7 : Symbol(p7, Decl(predicateSemantics.ts, 27, 5)) + +const p8 = (class foo { }) && null; +>p8 : Symbol(p8, Decl(predicateSemantics.ts, 28, 5)) +>foo : Symbol(foo, Decl(predicateSemantics.ts, 28, 12)) + +const p9 = (class foo { }) || null; +>p9 : Symbol(p9, Decl(predicateSemantics.ts, 29, 5)) +>foo : Symbol(foo, Decl(predicateSemantics.ts, 29, 12)) diff --git a/tests/baselines/reference/predicateSemantics.types b/tests/baselines/reference/predicateSemantics.types index 7890cb5cd346d..3d8dab75361cd 100644 --- a/tests/baselines/reference/predicateSemantics.types +++ b/tests/baselines/reference/predicateSemantics.types @@ -94,4 +94,70 @@ if (!!true) { } +// Should be OK (special cases) +while (0) { } +>0 : 0 +> : ^ + +while (1) { } +>1 : 1 +> : ^ + +while (true) { } +>true : true +> : ^^^^ + +while (false) { } +>false : false +> : ^^^^^ + +const p5 = {} ?? null; +>p5 : {} +> : ^^ +>{} ?? null : {} +> : ^^ +>{} : {} +> : ^^ + +const p6 = 0 > 1 ?? null; +>p6 : boolean +> : ^^^^^^^ +>0 > 1 ?? null : boolean +> : ^^^^^^^ +>0 > 1 : boolean +> : ^^^^^^^ +>0 : 0 +> : ^ +>1 : 1 +> : ^ + +const p7 = null ?? null; +>p7 : any +> : ^^^ +>null ?? null : null +> : ^^^^ + +const p8 = (class foo { }) && null; +>p8 : any +> : ^^^ +>(class foo { }) && null : null +> : ^^^^ +>(class foo { }) : typeof foo +> : ^^^^^^^^^^ +>class foo { } : typeof foo +> : ^^^^^^^^^^ +>foo : typeof foo +> : ^^^^^^^^^^ + +const p9 = (class foo { }) || null; +>p9 : typeof foo +> : ^^^^^^^^^^ +>(class foo { }) || null : typeof foo +> : ^^^^^^^^^^ +>(class foo { }) : typeof foo +> : ^^^^^^^^^^ +>class foo { } : typeof foo +> : ^^^^^^^^^^ +>foo : typeof foo +> : ^^^^^^^^^^ diff --git a/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.errors.txt b/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.errors.txt index 4bae3c1aa1868..aed0d9c6b8c59 100644 --- a/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.errors.txt +++ b/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.errors.txt @@ -1,4 +1,4 @@ -prefixUnaryOperatorsOnExportedVariables.ts(19,5): error TS2870: This expression is always falsy. Did you mean to test something else? +prefixUnaryOperatorsOnExportedVariables.ts(19,5): error TS2873: This kind of expression is always falsy. ==== prefixUnaryOperatorsOnExportedVariables.ts (1 errors) ==== @@ -22,7 +22,7 @@ prefixUnaryOperatorsOnExportedVariables.ts(19,5): error TS2870: This expression if (void x) { ~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. } diff --git a/tests/baselines/reference/primitiveMembers.errors.txt b/tests/baselines/reference/primitiveMembers.errors.txt index 4bd235fb0b5f0..a68f220c4244b 100644 --- a/tests/baselines/reference/primitiveMembers.errors.txt +++ b/tests/baselines/reference/primitiveMembers.errors.txt @@ -1,7 +1,7 @@ primitiveMembers.ts(5,3): error TS2339: Property 'toBAZ' does not exist on type 'number'. primitiveMembers.ts(11,1): error TS2322: Type 'Number' is not assignable to type 'number'. 'number' is a primitive, but 'Number' is a wrapper object. Prefer using 'number' when possible. -primitiveMembers.ts(21,10): error TS2869: This expression is always truthy. Did you mean to test something else? +primitiveMembers.ts(21,10): error TS2872: This kind of expression is always truthy. ==== primitiveMembers.ts (3 errors) ==== @@ -32,7 +32,7 @@ primitiveMembers.ts(21,10): error TS2869: This expression is always truthy. Did var n3 = 5 || {}; ~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. class baz { public bar(): void { }; } diff --git a/tests/baselines/reference/shebangError.errors.txt b/tests/baselines/reference/shebangError.errors.txt index 0f6c1d9aafb19..63d8730735c6a 100644 --- a/tests/baselines/reference/shebangError.errors.txt +++ b/tests/baselines/reference/shebangError.errors.txt @@ -1,6 +1,6 @@ shebangError.ts(2,1): error TS18026: '#!' can only be used at the start of a file. shebangError.ts(2,2): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. -shebangError.ts(2,3): error TS2869: This expression is always truthy. Did you mean to test something else? +shebangError.ts(2,3): error TS2872: This kind of expression is always truthy. shebangError.ts(2,12): error TS2304: Cannot find name 'env'. shebangError.ts(2,16): error TS1005: ';' expected. shebangError.ts(2,16): error TS2304: Cannot find name 'node'. @@ -14,7 +14,7 @@ shebangError.ts(2,16): error TS2304: Cannot find name 'node'. ~~~~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. ~~~~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. ~~~ !!! error TS2304: Cannot find name 'env'. ~~~~ diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt index eeb6cb9a0ce78..cf9ca906d7fa5 100644 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt @@ -1,17 +1,17 @@ stringLiteralsWithSwitchStatements03.ts(10,10): error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. Type '"baz"' is not comparable to type '"foo"'. -stringLiteralsWithSwitchStatements03.ts(10,34): error TS2869: This expression is always truthy. Did you mean to test something else? +stringLiteralsWithSwitchStatements03.ts(10,34): error TS2872: This kind of expression is always truthy. stringLiteralsWithSwitchStatements03.ts(12,10): error TS2678: Type '"bar"' is not comparable to type '"foo"'. stringLiteralsWithSwitchStatements03.ts(14,10): error TS2678: Type '"baz"' is not comparable to type '"foo"'. stringLiteralsWithSwitchStatements03.ts(14,11): error TS2695: Left side of comma operator is unused and has no side effects. stringLiteralsWithSwitchStatements03.ts(14,11): error TS2695: Left side of comma operator is unused and has no side effects. -stringLiteralsWithSwitchStatements03.ts(18,12): error TS2869: This expression is always truthy. Did you mean to test something else? +stringLiteralsWithSwitchStatements03.ts(18,12): error TS2872: This kind of expression is always truthy. stringLiteralsWithSwitchStatements03.ts(20,10): error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. Type '"baz"' is not comparable to type '"foo"'. -stringLiteralsWithSwitchStatements03.ts(20,12): error TS2869: This expression is always truthy. Did you mean to test something else? +stringLiteralsWithSwitchStatements03.ts(20,12): error TS2872: This kind of expression is always truthy. stringLiteralsWithSwitchStatements03.ts(22,10): error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. Type '"baz"' is not comparable to type '"foo"'. -stringLiteralsWithSwitchStatements03.ts(23,10): error TS2869: This expression is always truthy. Did you mean to test something else? +stringLiteralsWithSwitchStatements03.ts(23,10): error TS2872: This kind of expression is always truthy. stringLiteralsWithSwitchStatements03.ts(23,10): error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. Type '"baz"' is not comparable to type '"foo"'. @@ -31,7 +31,7 @@ stringLiteralsWithSwitchStatements03.ts(23,10): error TS2678: Type '"bar" | "baz !!! error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. !!! error TS2678: Type '"baz"' is not comparable to type '"foo"'. ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. break; case (("bar")): ~~~~~~~~~ @@ -49,14 +49,14 @@ stringLiteralsWithSwitchStatements03.ts(23,10): error TS2678: Type '"bar" | "baz break; case (("foo" || ("bar"))): ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. break; case (("bar" || ("baz"))): ~~~~~~~~~~~~~~~~~~~~ !!! error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. !!! error TS2678: Type '"baz"' is not comparable to type '"foo"'. ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. break; case z || "baz": ~~~~~~~~~~ @@ -64,7 +64,7 @@ stringLiteralsWithSwitchStatements03.ts(23,10): error TS2678: Type '"bar" | "baz !!! error TS2678: Type '"baz"' is not comparable to type '"foo"'. case "baz" || z: ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. ~~~~~~~~~~ !!! error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. !!! error TS2678: Type '"baz"' is not comparable to type '"foo"'. diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements04.errors.txt b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.errors.txt index c25a691e88ac7..981a8cdea647b 100644 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements04.errors.txt +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.errors.txt @@ -3,11 +3,11 @@ stringLiteralsWithSwitchStatements04.ts(9,10): error TS2695: Left side of comma stringLiteralsWithSwitchStatements04.ts(11,10): error TS2695: Left side of comma operator is unused and has no side effects. stringLiteralsWithSwitchStatements04.ts(11,10): error TS2678: Type '"baz"' is not comparable to type '"foo" | "bar"'. stringLiteralsWithSwitchStatements04.ts(13,10): error TS2695: Left side of comma operator is unused and has no side effects. -stringLiteralsWithSwitchStatements04.ts(15,10): error TS2869: This expression is always truthy. Did you mean to test something else? -stringLiteralsWithSwitchStatements04.ts(17,10): error TS2869: This expression is always truthy. Did you mean to test something else? -stringLiteralsWithSwitchStatements04.ts(17,20): error TS2869: This expression is always truthy. Did you mean to test something else? -stringLiteralsWithSwitchStatements04.ts(19,10): error TS2869: This expression is always truthy. Did you mean to test something else? -stringLiteralsWithSwitchStatements04.ts(19,20): error TS2869: This expression is always truthy. Did you mean to test something else? +stringLiteralsWithSwitchStatements04.ts(15,10): error TS2872: This kind of expression is always truthy. +stringLiteralsWithSwitchStatements04.ts(17,10): error TS2872: This kind of expression is always truthy. +stringLiteralsWithSwitchStatements04.ts(17,20): error TS2872: This kind of expression is always truthy. +stringLiteralsWithSwitchStatements04.ts(19,10): error TS2872: This kind of expression is always truthy. +stringLiteralsWithSwitchStatements04.ts(19,20): error TS2872: This kind of expression is always truthy. ==== stringLiteralsWithSwitchStatements04.ts (10 errors) ==== @@ -37,19 +37,19 @@ stringLiteralsWithSwitchStatements04.ts(19,20): error TS2869: This expression is break; case "baz" && "bar": ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. break; case "baz" && ("foo" || "bar"): ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. break; case "bar" && ("baz" || "bar"): ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. ~~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. break; } \ No newline at end of file diff --git a/tests/baselines/reference/symbolType11.errors.txt b/tests/baselines/reference/symbolType11.errors.txt index 9b714271835e4..f4b6bfbaf92c9 100644 --- a/tests/baselines/reference/symbolType11.errors.txt +++ b/tests/baselines/reference/symbolType11.errors.txt @@ -1,4 +1,4 @@ -symbolType11.ts(7,1): error TS2869: This expression is always truthy. Did you mean to test something else? +symbolType11.ts(7,1): error TS2872: This kind of expression is always truthy. ==== symbolType11.ts (1 errors) ==== @@ -10,4 +10,4 @@ symbolType11.ts(7,1): error TS2869: This expression is always truthy. Did you me s || 1; ({}) || s; ~~~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? \ No newline at end of file +!!! error TS2872: This kind of expression is always truthy. \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardsInIfStatement.errors.txt b/tests/baselines/reference/typeGuardsInIfStatement.errors.txt index dd9b5577bfbda..be6a26b3a8e9a 100644 --- a/tests/baselines/reference/typeGuardsInIfStatement.errors.txt +++ b/tests/baselines/reference/typeGuardsInIfStatement.errors.txt @@ -1,4 +1,4 @@ -typeGuardsInIfStatement.ts(120,17): error TS2869: This expression is always truthy. Did you mean to test something else? +typeGuardsInIfStatement.ts(120,17): error TS2872: This kind of expression is always truthy. typeGuardsInIfStatement.ts(139,17): error TS2339: Property 'toString' does not exist on type 'never'. @@ -124,7 +124,7 @@ typeGuardsInIfStatement.ts(139,17): error TS2339: Property 'toString' does not e // change value of x x = 10 && x.toString() // number | boolean | string ~~ -!!! error TS2869: This expression is always truthy. Did you mean to test something else? +!!! error TS2872: This kind of expression is always truthy. ) : ( // do not change value diff --git a/tests/baselines/reference/voidAsOperator.errors.txt b/tests/baselines/reference/voidAsOperator.errors.txt index ea9a3ae16b367..ac892e130cc97 100644 --- a/tests/baselines/reference/voidAsOperator.errors.txt +++ b/tests/baselines/reference/voidAsOperator.errors.txt @@ -1,10 +1,10 @@ -voidAsOperator.ts(1,6): error TS2870: This expression is always falsy. Did you mean to test something else? +voidAsOperator.ts(1,6): error TS2873: This kind of expression is always falsy. ==== voidAsOperator.ts (1 errors) ==== if (!void 0 !== true) { ~~~~~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. } diff --git a/tests/baselines/reference/witness.errors.txt b/tests/baselines/reference/witness.errors.txt index 25ba45efaf4f3..603db90af980e 100644 --- a/tests/baselines/reference/witness.errors.txt +++ b/tests/baselines/reference/witness.errors.txt @@ -12,9 +12,9 @@ witness.ts(33,5): error TS2403: Subsequent variable declarations must have the s witness.ts(37,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'as1' must be of type 'any', but here has type 'number'. witness.ts(39,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'as2' must be of type 'any', but here has type 'number'. witness.ts(43,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'cnd1' must be of type 'any', but here has type 'number'. -witness.ts(50,11): error TS2870: This expression is always falsy. Did you mean to test something else? +witness.ts(50,11): error TS2873: This kind of expression is always falsy. witness.ts(57,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'and1' must be of type 'any', but here has type 'string'. -witness.ts(58,12): error TS2870: This expression is always falsy. Did you mean to test something else? +witness.ts(58,12): error TS2873: This kind of expression is always falsy. witness.ts(68,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'fnCallResult' must be of type 'never', but here has type 'any'. witness.ts(110,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'propAcc1' must be of type 'any', but here has type '{ m: any; }'. witness.ts(121,14): error TS2729: Property 'n' is used before its initialization. @@ -108,7 +108,7 @@ witness.ts(128,19): error TS2729: Property 'q' is used before its initialization var or1: any; var or2 = '' || or2; ~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var or2: any; var or3 = or3 || or3; var or3: any; @@ -121,7 +121,7 @@ witness.ts(128,19): error TS2729: Property 'q' is used before its initialization !!! related TS6203 witness.ts:56:5: 'and1' was also declared here. var and2 = '' && and2; ~~ -!!! error TS2870: This expression is always falsy. Did you mean to test something else? +!!! error TS2873: This kind of expression is always falsy. var and2: any; var and3 = and3 && and3; var and3: any; diff --git a/tests/cases/compiler/predicateSemantics.ts b/tests/cases/compiler/predicateSemantics.ts index b8999c32afecc..47ec505b23c39 100644 --- a/tests/cases/compiler/predicateSemantics.ts +++ b/tests/cases/compiler/predicateSemantics.ts @@ -17,3 +17,14 @@ if (!!true) { } +// Should be OK (special cases) +while (0) { } +while (1) { } +while (true) { } +while (false) { } + +const p5 = {} ?? null; +const p6 = 0 > 1 ?? null; +const p7 = null ?? null; +const p8 = (class foo { }) && null; +const p9 = (class foo { }) || null; From 3388e4cc64649f2ddee86b9639d35df62b16029e Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 22 Jul 2024 09:52:19 -0700 Subject: [PATCH 06/12] Format --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9a7fe8ec5a0e6..d03fcda6a11f7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -44275,7 +44275,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { node, semantics === PredicateSemantics.Always ? Diagnostics.This_kind_of_expression_is_always_truthy : - Diagnostics.This_kind_of_expression_is_always_falsy + Diagnostics.This_kind_of_expression_is_always_falsy, ); } } From 6d0da7aadbd4b81ae69df907197f2dd940144e3c Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 22 Jul 2024 09:56:21 -0700 Subject: [PATCH 07/12] Add @internal --- src/compiler/utilities.ts | 1 + tests/baselines/reference/api/typescript.d.ts | 1 - ...nericParentMethodPropUnions-100.errors.txt | 98 ------------------- 3 files changed, 1 insertion(+), 99 deletions(-) delete mode 100644 tests/baselines/reference/mergeSameGenericParentMethodPropUnions-100.errors.txt diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 2bcd1131cd5eb..49258c7304d0d 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -7187,6 +7187,7 @@ export function modifierToFlag(token: SyntaxKind): ModifierFlags { return ModifierFlags.None; } +/** @internal */ export function isBinaryLogicalOperator(token: SyntaxKind): boolean { return token === SyntaxKind.BarBarToken || token === SyntaxKind.AmpersandAmpersandToken; } diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 493c3f0002e85..3855078b1f285 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -8754,7 +8754,6 @@ declare namespace ts { * ``` */ function getJSDocCommentsAndTags(hostNode: Node): readonly (JSDoc | JSDocTag)[]; - function isBinaryLogicalOperator(token: SyntaxKind): boolean; /** * Create an external source map source file reference */ diff --git a/tests/baselines/reference/mergeSameGenericParentMethodPropUnions-100.errors.txt b/tests/baselines/reference/mergeSameGenericParentMethodPropUnions-100.errors.txt deleted file mode 100644 index 59f9311e35fd0..0000000000000 --- a/tests/baselines/reference/mergeSameGenericParentMethodPropUnions-100.errors.txt +++ /dev/null @@ -1,98 +0,0 @@ --incompasig-110.ts(9,20): error TS2349: This expression is not callable. - Each member of the union type '{ (cb: (x: number) => number): number[]; (cb: (x: number) => U): U[]; } | { (cb: (x: string) => string): string[]; (cb: (x: string) => U): U[]; }' has signatures, but none of those signatures are compatible with each other. --incompasig-110.ts(9,22): error TS7006: Parameter 'x' implicitly has an 'any' type. --incompasig-111.ts(9,20): error TS2349: This expression is not callable. - Each member of the union type '{ (cb: (a: number, x: number) => number): number[]; (cb: (a: U, x: number) => U, init: U): U[]; } | { (cb: (a: bigint, x: bigint) => bigint): bigint[]; (cb: (a: U, x: bigint) => U, init: U): U[]; }' has signatures, but none of those signatures are compatible with each other. --incompasig-111.ts(9,33): error TS7006: Parameter 'x' implicitly has an 'any' type. --incompasig-200.ts(7,11): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'never'. - Type 'string' is not assignable to type 'never'. --incompasig-200.ts(9,8): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'never'. - Type 'string' is not assignable to type 'never'. --incompasig-200.ts(11,11): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'never'. - Type 'string' is not assignable to type 'never'. --incompasig-200.ts(13,14): error TS2769: No overload matches this call. - Overload 1 of 3, '(start: number, deleteCount: number, ...items: string[]): string[] | number[]', gave the following error. - Argument of type 'string | number' is not assignable to parameter of type 'string'. - Type 'number' is not assignable to type 'string'. - Overload 2 of 3, '(start: number, deleteCount: number, ...items: number[]): string[] | number[]', gave the following error. - Argument of type 'string | number' is not assignable to parameter of type 'number'. - Type 'string' is not assignable to type 'number'. - - -==== -incompasig-200.ts (4 errors) ==== - namespace ns4 { - - declare var y: Array|Array; - - declare const a: number|string; - - y.indexOf(a); - ~ -!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'never'. -!!! error TS2345: Type 'string' is not assignable to type 'never'. - - y.push(a); - ~ -!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'never'. -!!! error TS2345: Type 'string' is not assignable to type 'never'. - - y.unshift(a); - ~ -!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'never'. -!!! error TS2345: Type 'string' is not assignable to type 'never'. - - y.splice(1,1,a); - ~ -!!! error TS2769: No overload matches this call. -!!! error TS2769: Overload 1 of 3, '(start: number, deleteCount: number, ...items: string[]): string[] | number[]', gave the following error. -!!! error TS2769: Argument of type 'string | number' is not assignable to parameter of type 'string'. -!!! error TS2769: Type 'number' is not assignable to type 'string'. -!!! error TS2769: Overload 2 of 3, '(start: number, deleteCount: number, ...items: number[]): string[] | number[]', gave the following error. -!!! error TS2769: Argument of type 'string | number' is not assignable to parameter of type 'number'. -!!! error TS2769: Type 'string' is not assignable to type 'number'. - - } - - - /**********************/ -==== -incompasig-110.ts (2 errors) ==== - namespace ns0 { - - interface Test110 { - f(cb:(x:T)=>T):T[]; - f(cb:(x:T)=>U):U[]; - } - - declare const arr: Test110 | Test110; - const result = arr.f(x => x); - ~ -!!! error TS2349: This expression is not callable. -!!! error TS2349: Each member of the union type '{ (cb: (x: number) => number): number[]; (cb: (x: number) => U): U[]; } | { (cb: (x: string) => string): string[]; (cb: (x: string) => U): U[]; }' has signatures, but none of those signatures are compatible with each other. - ~ -!!! error TS7006: Parameter 'x' implicitly has an 'any' type. - - } - - - /**********************/ -==== -incompasig-111.ts (2 errors) ==== - namespace ns1 { - - interface Test111 { - f(cb:(a:T, x:T)=>T):T[]; - f(cb:(a:U, x:T)=>U,init:U):U[]; - } - - declare const arr: Test111 | Test111; - const result = arr.f((a:bigint, x) => a * BigInt(x), 1n); - ~ -!!! error TS2349: This expression is not callable. -!!! error TS2349: Each member of the union type '{ (cb: (a: number, x: number) => number): number[]; (cb: (a: U, x: number) => U, init: U): U[]; } | { (cb: (a: bigint, x: bigint) => bigint): bigint[]; (cb: (a: U, x: bigint) => U, init: U): U[]; }' has signatures, but none of those signatures are compatible with each other. - ~ -!!! error TS7006: Parameter 'x' implicitly has an 'any' type. - - } - - - - \ No newline at end of file From 64d27ce5ad51da702247085d7abcced622629ba7 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 22 Jul 2024 10:56:17 -0700 Subject: [PATCH 08/12] Handle not-undefined undefineds --- src/compiler/checker.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d03fcda6a11f7..d0f8577d5447b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -39619,16 +39619,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return PredicateSemantics.Sometimes; } return PredicateSemantics.Never; - case SyntaxKind.NullKeyword: - return PredicateSemantics.Always; case SyntaxKind.TypeAssertionExpression: case SyntaxKind.AsExpression: case SyntaxKind.ParenthesizedExpression: return getSyntacticNullishnessSemantics((node as OuterExpression).expression); case SyntaxKind.ConditionalExpression: return getSyntacticNullishnessSemantics((node as ConditionalExpression).whenTrue) | getSyntacticNullishnessSemantics((node as ConditionalExpression).whenFalse); + case SyntaxKind.NullKeyword: + return PredicateSemantics.Always; case SyntaxKind.Identifier: - if ((node as Identifier).escapedText === "undefined") { + if (((node as Identifier).escapedText === "undefined") && (getTypeOfExpression(node as Identifier) === undefinedWideningType)) { return PredicateSemantics.Always; } return PredicateSemantics.Sometimes; @@ -44302,6 +44302,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { case SyntaxKind.RegularExpressionLiteral: return PredicateSemantics.Always; case SyntaxKind.VoidExpression: + case SyntaxKind.NullKeyword: return PredicateSemantics.Never; case SyntaxKind.NoSubstitutionTemplateLiteral: case SyntaxKind.StringLiteral: @@ -44313,7 +44314,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { case SyntaxKind.ConditionalExpression: return getSyntacticTruthySemantics((node as ConditionalExpression).whenTrue) | getSyntacticTruthySemantics((node as ConditionalExpression).whenFalse); case SyntaxKind.Identifier: - if ((node as Identifier).escapedText === "undefined") { + if (((node as Identifier).escapedText === "undefined") && (getTypeOfExpression(node as Identifier) === undefinedWideningType)) { return PredicateSemantics.Never; } return PredicateSemantics.Sometimes; From f988a056dc792d1b1c80d43febbf153cebd3aab2 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 22 Jul 2024 11:25:45 -0700 Subject: [PATCH 09/12] Resolve identifiers to check for undefined --- src/compiler/checker.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d0f8577d5447b..33c78daede155 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -39628,7 +39628,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { case SyntaxKind.NullKeyword: return PredicateSemantics.Always; case SyntaxKind.Identifier: - if (((node as Identifier).escapedText === "undefined") && (getTypeOfExpression(node as Identifier) === undefinedWideningType)) { + if (getResolvedSymbol(node as Identifier) === undefinedSymbol) { return PredicateSemantics.Always; } return PredicateSemantics.Sometimes; @@ -44314,7 +44314,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { case SyntaxKind.ConditionalExpression: return getSyntacticTruthySemantics((node as ConditionalExpression).whenTrue) | getSyntacticTruthySemantics((node as ConditionalExpression).whenFalse); case SyntaxKind.Identifier: - if (((node as Identifier).escapedText === "undefined") && (getTypeOfExpression(node as Identifier) === undefinedWideningType)) { + if (getResolvedSymbol(node as Identifier) === undefinedSymbol) { return PredicateSemantics.Never; } return PredicateSemantics.Sometimes; From b786cf233897979285986330dc06ce85710b5ad7 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 22 Jul 2024 11:44:23 -0700 Subject: [PATCH 10/12] Baseline update --- .../aliasUsageInOrExpression.errors.txt | 31 ++++++++++++++ ...tCommonTypeWithContextualTyping.errors.txt | 26 ++++++++++++ .../bestCommonTypeWithContextualTyping.types | 3 ++ ...ionalOperatorConditoinIsAnyType.errors.txt | 17 +++++++- ...uringAssignmentWithExportedName.errors.txt | 40 +++++++++++++++++++ ...tructuringAssignmentWithExportedName.types | 37 +++++++++++++++++ .../reference/ifDoWhileStatements.errors.txt | 11 ++++- .../reference/initializersWidened.errors.txt | 8 +++- ...logicalAndOperatorWithEveryType.errors.txt | 32 ++++++++++++++- ...icalNotOperatorWithAnyOtherType.errors.txt | 5 ++- .../logicalOrOperatorWithEveryType.errors.txt | 32 ++++++++++++++- .../reference/voidAsOperator.errors.txt | 5 ++- 12 files changed, 240 insertions(+), 7 deletions(-) create mode 100644 tests/baselines/reference/aliasUsageInOrExpression.errors.txt create mode 100644 tests/baselines/reference/bestCommonTypeWithContextualTyping.errors.txt create mode 100644 tests/baselines/reference/destructuringAssignmentWithExportedName.errors.txt diff --git a/tests/baselines/reference/aliasUsageInOrExpression.errors.txt b/tests/baselines/reference/aliasUsageInOrExpression.errors.txt new file mode 100644 index 0000000000000..2ac162439c2c7 --- /dev/null +++ b/tests/baselines/reference/aliasUsageInOrExpression.errors.txt @@ -0,0 +1,31 @@ +aliasUsageInOrExpression_main.ts(10,40): error TS2873: This kind of expression is always falsy. +aliasUsageInOrExpression_main.ts(11,40): error TS2873: This kind of expression is always falsy. + + +==== aliasUsageInOrExpression_main.ts (2 errors) ==== + import Backbone = require("./aliasUsageInOrExpression_backbone"); + import moduleA = require("./aliasUsageInOrExpression_moduleA"); + interface IHasVisualizationModel { + VisualizationModel: typeof Backbone.Model; + } + var i: IHasVisualizationModel; + var d1 = i || moduleA; + var d2: IHasVisualizationModel = i || moduleA; + var d2: IHasVisualizationModel = moduleA || i; + var e: { x: IHasVisualizationModel } = <{ x: IHasVisualizationModel }>null || { x: moduleA }; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2873: This kind of expression is always falsy. + var f: { x: IHasVisualizationModel } = <{ x: IHasVisualizationModel }>null ? { x: moduleA } : null; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2873: This kind of expression is always falsy. +==== aliasUsageInOrExpression_backbone.ts (0 errors) ==== + export class Model { + public someData: string; + } + +==== aliasUsageInOrExpression_moduleA.ts (0 errors) ==== + import Backbone = require("./aliasUsageInOrExpression_backbone"); + export class VisualizationModel extends Backbone.Model { + // interesting stuff here + } + \ No newline at end of file diff --git a/tests/baselines/reference/bestCommonTypeWithContextualTyping.errors.txt b/tests/baselines/reference/bestCommonTypeWithContextualTyping.errors.txt new file mode 100644 index 0000000000000..2aafdf2154b9a --- /dev/null +++ b/tests/baselines/reference/bestCommonTypeWithContextualTyping.errors.txt @@ -0,0 +1,26 @@ +bestCommonTypeWithContextualTyping.ts(19,31): error TS2873: This kind of expression is always falsy. + + +==== bestCommonTypeWithContextualTyping.ts (1 errors) ==== + interface Contextual { + dummy; + p?: number; + } + + interface Ellement { + dummy; + p: any; + } + + var e: Ellement; + + // All of these should pass. Neither type is a supertype of the other, but the RHS should + // always use Ellement in these examples (not Contextual). Because Ellement is assignable + // to Contextual, no errors. + var arr: Contextual[] = [e]; // Ellement[] + var obj: { [s: string]: Contextual } = { s: e }; // { s: Ellement; [s: string]: Ellement } + + var conditional: Contextual = null ? e : e; // Ellement + ~~~~ +!!! error TS2873: This kind of expression is always falsy. + var contextualOr: Contextual = e || e; // Ellement \ No newline at end of file diff --git a/tests/baselines/reference/bestCommonTypeWithContextualTyping.types b/tests/baselines/reference/bestCommonTypeWithContextualTyping.types index 68b67e4389eae..735202dcd63e1 100644 --- a/tests/baselines/reference/bestCommonTypeWithContextualTyping.types +++ b/tests/baselines/reference/bestCommonTypeWithContextualTyping.types @@ -4,6 +4,7 @@ interface Contextual { dummy; >dummy : any +> : ^^^ p?: number; >p : number @@ -13,9 +14,11 @@ interface Contextual { interface Ellement { dummy; >dummy : any +> : ^^^ p: any; >p : any +> : ^^^ } var e: Ellement; diff --git a/tests/baselines/reference/conditionalOperatorConditoinIsAnyType.errors.txt b/tests/baselines/reference/conditionalOperatorConditoinIsAnyType.errors.txt index a42ed0393085a..bd7989896dfb1 100644 --- a/tests/baselines/reference/conditionalOperatorConditoinIsAnyType.errors.txt +++ b/tests/baselines/reference/conditionalOperatorConditoinIsAnyType.errors.txt @@ -1,15 +1,20 @@ +conditionalOperatorConditoinIsAnyType.ts(26,1): error TS2873: This kind of expression is always falsy. +conditionalOperatorConditoinIsAnyType.ts(27,1): error TS2873: This kind of expression is always falsy. conditionalOperatorConditoinIsAnyType.ts(28,1): error TS2873: This kind of expression is always falsy. conditionalOperatorConditoinIsAnyType.ts(29,1): error TS2872: This kind of expression is always truthy. conditionalOperatorConditoinIsAnyType.ts(30,1): error TS2872: This kind of expression is always truthy. conditionalOperatorConditoinIsAnyType.ts(31,1): error TS2873: This kind of expression is always falsy. +conditionalOperatorConditoinIsAnyType.ts(49,20): error TS2873: This kind of expression is always falsy. +conditionalOperatorConditoinIsAnyType.ts(50,24): error TS2873: This kind of expression is always falsy. conditionalOperatorConditoinIsAnyType.ts(51,23): error TS2873: This kind of expression is always falsy. conditionalOperatorConditoinIsAnyType.ts(52,23): error TS2872: This kind of expression is always truthy. conditionalOperatorConditoinIsAnyType.ts(53,23): error TS2872: This kind of expression is always truthy. +conditionalOperatorConditoinIsAnyType.ts(54,32): error TS2873: This kind of expression is always falsy. conditionalOperatorConditoinIsAnyType.ts(55,32): error TS2873: This kind of expression is always falsy. conditionalOperatorConditoinIsAnyType.ts(56,32): error TS2872: This kind of expression is always truthy. -==== conditionalOperatorConditoinIsAnyType.ts (9 errors) ==== +==== conditionalOperatorConditoinIsAnyType.ts (14 errors) ==== //Cond ? Expr1 : Expr2, Cond is of any type, Expr1 and Expr2 have the same type var condAny: any; var x: any; @@ -36,7 +41,11 @@ conditionalOperatorConditoinIsAnyType.ts(56,32): error TS2872: This kind of expr //Cond is an any type literal null ? exprAny1 : exprAny2; + ~~~~ +!!! error TS2873: This kind of expression is always falsy. null ? exprBoolean1 : exprBoolean2; + ~~~~ +!!! error TS2873: This kind of expression is always falsy. undefined ? exprNumber1 : exprNumber2; ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. @@ -67,7 +76,11 @@ conditionalOperatorConditoinIsAnyType.ts(56,32): error TS2872: This kind of expr var resultIsStringOrBoolean1 = condAny ? exprString1 : exprBoolean1; // union var resultIsAny2 = null ? exprAny1 : exprAny2; + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var resultIsBoolean2 = null ? exprBoolean1 : exprBoolean2; + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var resultIsNumber2 = undefined ? exprNumber1 : exprNumber2; ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. @@ -78,6 +91,8 @@ conditionalOperatorConditoinIsAnyType.ts(56,32): error TS2872: This kind of expr ~~~~~~~~~~~~~~~~~ !!! error TS2872: This kind of expression is always truthy. var resultIsStringOrBoolean2 = null ? exprString1 : exprBoolean1; // union + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var resultIsStringOrBoolean3 = undefined ? exprString1 : exprBoolean1; // union ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. diff --git a/tests/baselines/reference/destructuringAssignmentWithExportedName.errors.txt b/tests/baselines/reference/destructuringAssignmentWithExportedName.errors.txt new file mode 100644 index 0000000000000..bda58012cb4cc --- /dev/null +++ b/tests/baselines/reference/destructuringAssignmentWithExportedName.errors.txt @@ -0,0 +1,40 @@ +destructuringAssignmentWithExportedName.ts(8,5): error TS2873: This kind of expression is always falsy. +destructuringAssignmentWithExportedName.ts(11,10): error TS2873: This kind of expression is always falsy. +destructuringAssignmentWithExportedName.ts(14,10): error TS2873: This kind of expression is always falsy. +destructuringAssignmentWithExportedName.ts(17,10): error TS2873: This kind of expression is always falsy. + + +==== destructuringAssignmentWithExportedName.ts (4 errors) ==== + export let exportedFoo: any; + let nonexportedFoo: any; + + // sanity checks + exportedFoo = null; + nonexportedFoo = null; + + if (null as any) { + ~~~~~~~~~~~ +!!! error TS2873: This kind of expression is always falsy. + ({ exportedFoo, nonexportedFoo } = null as any); + } + else if (null as any) { + ~~~~~~~~~~~ +!!! error TS2873: This kind of expression is always falsy. + ({ foo: exportedFoo, bar: nonexportedFoo } = null as any); + } + else if (null as any) { + ~~~~~~~~~~~ +!!! error TS2873: This kind of expression is always falsy. + ({ foo: { bar: exportedFoo, baz: nonexportedFoo } } = null as any); + } + else if (null as any) { + ~~~~~~~~~~~ +!!! error TS2873: This kind of expression is always falsy. + ([exportedFoo, nonexportedFoo] = null as any); + } + else { + ([[exportedFoo, nonexportedFoo]] = null as any); + } + + export { nonexportedFoo }; + export { exportedFoo as foo, nonexportedFoo as nfoo }; \ No newline at end of file diff --git a/tests/baselines/reference/destructuringAssignmentWithExportedName.types b/tests/baselines/reference/destructuringAssignmentWithExportedName.types index ee27a172c79a4..a6f6c9f51b208 100644 --- a/tests/baselines/reference/destructuringAssignmentWithExportedName.types +++ b/tests/baselines/reference/destructuringAssignmentWithExportedName.types @@ -3,53 +3,74 @@ === destructuringAssignmentWithExportedName.ts === export let exportedFoo: any; >exportedFoo : any +> : ^^^ let nonexportedFoo: any; >nonexportedFoo : any +> : ^^^ // sanity checks exportedFoo = null; >exportedFoo = null : null > : ^^^^ >exportedFoo : any +> : ^^^ nonexportedFoo = null; >nonexportedFoo = null : null > : ^^^^ >nonexportedFoo : any +> : ^^^ if (null as any) { >null as any : any +> : ^^^ ({ exportedFoo, nonexportedFoo } = null as any); >({ exportedFoo, nonexportedFoo } = null as any) : any +> : ^^^ >{ exportedFoo, nonexportedFoo } = null as any : any +> : ^^^ >{ exportedFoo, nonexportedFoo } : { exportedFoo: any; nonexportedFoo: any; } > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >exportedFoo : any +> : ^^^ >nonexportedFoo : any +> : ^^^ >null as any : any +> : ^^^ } else if (null as any) { >null as any : any +> : ^^^ ({ foo: exportedFoo, bar: nonexportedFoo } = null as any); >({ foo: exportedFoo, bar: nonexportedFoo } = null as any) : any +> : ^^^ >{ foo: exportedFoo, bar: nonexportedFoo } = null as any : any +> : ^^^ >{ foo: exportedFoo, bar: nonexportedFoo } : { foo: any; bar: any; } > : ^^^^^^^^^^^^^^^^^^^^^^^ >foo : any +> : ^^^ >exportedFoo : any +> : ^^^ >bar : any +> : ^^^ >nonexportedFoo : any +> : ^^^ >null as any : any +> : ^^^ } else if (null as any) { >null as any : any +> : ^^^ ({ foo: { bar: exportedFoo, baz: nonexportedFoo } } = null as any); >({ foo: { bar: exportedFoo, baz: nonexportedFoo } } = null as any) : any +> : ^^^ >{ foo: { bar: exportedFoo, baz: nonexportedFoo } } = null as any : any +> : ^^^ >{ foo: { bar: exportedFoo, baz: nonexportedFoo } } : { foo: { bar: any; baz: any; }; } > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >foo : { bar: any; baz: any; } @@ -57,34 +78,50 @@ else if (null as any) { >{ bar: exportedFoo, baz: nonexportedFoo } : { bar: any; baz: any; } > : ^^^^^^^^^^^^^^^^^^^^^^^ >bar : any +> : ^^^ >exportedFoo : any +> : ^^^ >baz : any +> : ^^^ >nonexportedFoo : any +> : ^^^ >null as any : any +> : ^^^ } else if (null as any) { >null as any : any +> : ^^^ ([exportedFoo, nonexportedFoo] = null as any); >([exportedFoo, nonexportedFoo] = null as any) : any +> : ^^^ >[exportedFoo, nonexportedFoo] = null as any : any +> : ^^^ >[exportedFoo, nonexportedFoo] : [any, any] > : ^^^^^^^^^^ >exportedFoo : any +> : ^^^ >nonexportedFoo : any +> : ^^^ >null as any : any +> : ^^^ } else { ([[exportedFoo, nonexportedFoo]] = null as any); >([[exportedFoo, nonexportedFoo]] = null as any) : any +> : ^^^ >[[exportedFoo, nonexportedFoo]] = null as any : any +> : ^^^ >[[exportedFoo, nonexportedFoo]] : [[any, any]] > : ^^^^^^^^^^^^ >[exportedFoo, nonexportedFoo] : [any, any] > : ^^^^^^^^^^ >exportedFoo : any +> : ^^^ >nonexportedFoo : any +> : ^^^ >null as any : any +> : ^^^ } export { nonexportedFoo }; diff --git a/tests/baselines/reference/ifDoWhileStatements.errors.txt b/tests/baselines/reference/ifDoWhileStatements.errors.txt index bbeaa9db15df4..c103478b4e640 100644 --- a/tests/baselines/reference/ifDoWhileStatements.errors.txt +++ b/tests/baselines/reference/ifDoWhileStatements.errors.txt @@ -1,3 +1,6 @@ +ifDoWhileStatements.ts(44,5): error TS2873: This kind of expression is always falsy. +ifDoWhileStatements.ts(45,8): error TS2873: This kind of expression is always falsy. +ifDoWhileStatements.ts(46,13): error TS2873: This kind of expression is always falsy. ifDoWhileStatements.ts(48,5): error TS2873: This kind of expression is always falsy. ifDoWhileStatements.ts(49,8): error TS2873: This kind of expression is always falsy. ifDoWhileStatements.ts(50,13): error TS2873: This kind of expression is always falsy. @@ -27,7 +30,7 @@ ifDoWhileStatements.ts(85,8): error TS2872: This kind of expression is always tr ifDoWhileStatements.ts(86,13): error TS2872: This kind of expression is always truthy. -==== ifDoWhileStatements.ts (27 errors) ==== +==== ifDoWhileStatements.ts (30 errors) ==== interface I { id: number; } @@ -72,8 +75,14 @@ ifDoWhileStatements.ts(86,13): error TS2872: This kind of expression is always t do { }while(true) if (null) { } + ~~~~ +!!! error TS2873: This kind of expression is always falsy. while (null) { } + ~~~~ +!!! error TS2873: This kind of expression is always falsy. do { }while(null) + ~~~~ +!!! error TS2873: This kind of expression is always falsy. if (undefined) { } ~~~~~~~~~ diff --git a/tests/baselines/reference/initializersWidened.errors.txt b/tests/baselines/reference/initializersWidened.errors.txt index 28a8315a1906e..d39383da36391 100644 --- a/tests/baselines/reference/initializersWidened.errors.txt +++ b/tests/baselines/reference/initializersWidened.errors.txt @@ -1,10 +1,12 @@ +initializersWidened.ts(18,10): error TS2873: This kind of expression is always falsy. initializersWidened.ts(19,10): error TS2873: This kind of expression is always falsy. initializersWidened.ts(20,10): error TS2873: This kind of expression is always falsy. +initializersWidened.ts(22,10): error TS2873: This kind of expression is always falsy. initializersWidened.ts(23,10): error TS2873: This kind of expression is always falsy. initializersWidened.ts(24,10): error TS2873: This kind of expression is always falsy. -==== initializersWidened.ts (4 errors) ==== +==== initializersWidened.ts (6 errors) ==== // these are widened to any at the point of assignment var x1 = null; @@ -23,6 +25,8 @@ initializersWidened.ts(24,10): error TS2873: This kind of expression is always f // widen only when all constituents of union are widening var x4 = null || null; + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var y4 = undefined || undefined; ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. @@ -31,6 +35,8 @@ initializersWidened.ts(24,10): error TS2873: This kind of expression is always f !!! error TS2873: This kind of expression is always falsy. var x5 = null || x2; + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var y5 = undefined || y2; ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. diff --git a/tests/baselines/reference/logicalAndOperatorWithEveryType.errors.txt b/tests/baselines/reference/logicalAndOperatorWithEveryType.errors.txt index 5ef762173ea3d..7f10b53cd3f30 100644 --- a/tests/baselines/reference/logicalAndOperatorWithEveryType.errors.txt +++ b/tests/baselines/reference/logicalAndOperatorWithEveryType.errors.txt @@ -1,26 +1,36 @@ logicalAndOperatorWithEveryType.ts(19,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalAndOperatorWithEveryType.ts(23,11): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(24,12): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(30,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalAndOperatorWithEveryType.ts(34,11): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(35,12): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(41,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalAndOperatorWithEveryType.ts(45,11): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(46,12): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(52,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalAndOperatorWithEveryType.ts(56,11): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(57,12): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(63,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalAndOperatorWithEveryType.ts(67,11): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(68,12): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(74,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalAndOperatorWithEveryType.ts(78,11): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(79,12): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(85,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalAndOperatorWithEveryType.ts(89,11): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(90,12): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(96,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalAndOperatorWithEveryType.ts(100,11): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(101,12): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(107,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalAndOperatorWithEveryType.ts(111,11): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(112,12): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(118,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalAndOperatorWithEveryType.ts(122,11): error TS2873: This kind of expression is always falsy. logicalAndOperatorWithEveryType.ts(123,12): error TS2873: This kind of expression is always falsy. -==== logicalAndOperatorWithEveryType.ts (20 errors) ==== +==== logicalAndOperatorWithEveryType.ts (30 errors) ==== // The && operator permits the operands to be of any type and produces a result of the same // type as the second operand. @@ -46,6 +56,8 @@ logicalAndOperatorWithEveryType.ts(123,12): error TS2873: This kind of expressio var ra7 = a7 && a1; var ra8 = a8 && a1; var ra9 = null && a1; + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var ra10 = undefined && a1; ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. @@ -61,6 +73,8 @@ logicalAndOperatorWithEveryType.ts(123,12): error TS2873: This kind of expressio var rb7 = a7 && a2; var rb8 = a8 && a2; var rb9 = null && a2; + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var rb10 = undefined && a2; ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. @@ -76,6 +90,8 @@ logicalAndOperatorWithEveryType.ts(123,12): error TS2873: This kind of expressio var rc7 = a7 && a3; var rc8 = a8 && a3; var rc9 = null && a3; + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var rc10 = undefined && a3; ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. @@ -91,6 +107,8 @@ logicalAndOperatorWithEveryType.ts(123,12): error TS2873: This kind of expressio var rd7 = a7 && a4; var rd8 = a8 && a4; var rd9 = null && a4; + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var rd10 = undefined && a4; ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. @@ -106,6 +124,8 @@ logicalAndOperatorWithEveryType.ts(123,12): error TS2873: This kind of expressio var re7 = a7 && a5; var re8 = a8 && a5; var re9 = null && a5; + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var re10 = undefined && a5; ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. @@ -121,6 +141,8 @@ logicalAndOperatorWithEveryType.ts(123,12): error TS2873: This kind of expressio var rf7 = a7 && a6; var rf8 = a8 && a6; var rf9 = null && a6; + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var rf10 = undefined && a6; ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. @@ -136,6 +158,8 @@ logicalAndOperatorWithEveryType.ts(123,12): error TS2873: This kind of expressio var rg7 = a7 && a7; var rg8 = a8 && a7; var rg9 = null && a7; + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var rg10 = undefined && a7; ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. @@ -151,6 +175,8 @@ logicalAndOperatorWithEveryType.ts(123,12): error TS2873: This kind of expressio var rh7 = a7 && a8; var rh8 = a8 && a8; var rh9 = null && a8; + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var rh10 = undefined && a8; ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. @@ -166,6 +192,8 @@ logicalAndOperatorWithEveryType.ts(123,12): error TS2873: This kind of expressio var ri7 = a7 && null; var ri8 = a8 && null; var ri9 = null && null; + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var ri10 = undefined && null; ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. @@ -181,6 +209,8 @@ logicalAndOperatorWithEveryType.ts(123,12): error TS2873: This kind of expressio var rj7 = a7 && undefined; var rj8 = a8 && undefined; var rj9 = null && undefined; + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var rj10 = undefined && undefined; ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. \ No newline at end of file diff --git a/tests/baselines/reference/logicalNotOperatorWithAnyOtherType.errors.txt b/tests/baselines/reference/logicalNotOperatorWithAnyOtherType.errors.txt index 09d91a27d6009..a6a8a41cdf887 100644 --- a/tests/baselines/reference/logicalNotOperatorWithAnyOtherType.errors.txt +++ b/tests/baselines/reference/logicalNotOperatorWithAnyOtherType.errors.txt @@ -1,11 +1,12 @@ logicalNotOperatorWithAnyOtherType.ts(33,25): error TS2873: This kind of expression is always falsy. +logicalNotOperatorWithAnyOtherType.ts(34,25): error TS2873: This kind of expression is always falsy. logicalNotOperatorWithAnyOtherType.ts(45,27): error TS2365: Operator '+' cannot be applied to types 'null' and 'undefined'. logicalNotOperatorWithAnyOtherType.ts(46,27): error TS2365: Operator '+' cannot be applied to types 'null' and 'null'. logicalNotOperatorWithAnyOtherType.ts(47,27): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. logicalNotOperatorWithAnyOtherType.ts(57,1): error TS2695: Left side of comma operator is unused and has no side effects. -==== logicalNotOperatorWithAnyOtherType.ts (5 errors) ==== +==== logicalNotOperatorWithAnyOtherType.ts (6 errors) ==== // ! operator on any type var ANY: any; @@ -42,6 +43,8 @@ logicalNotOperatorWithAnyOtherType.ts(57,1): error TS2695: Left side of comma op ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. var ResultIsBoolean8 = !null; + ~~~~ +!!! error TS2873: This kind of expression is always falsy. // any type expressions var ResultIsBoolean9 = !ANY2[0]; diff --git a/tests/baselines/reference/logicalOrOperatorWithEveryType.errors.txt b/tests/baselines/reference/logicalOrOperatorWithEveryType.errors.txt index 84d06759e4b80..86b419f8e4a9f 100644 --- a/tests/baselines/reference/logicalOrOperatorWithEveryType.errors.txt +++ b/tests/baselines/reference/logicalOrOperatorWithEveryType.errors.txt @@ -1,26 +1,36 @@ logicalOrOperatorWithEveryType.ts(21,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalOrOperatorWithEveryType.ts(25,11): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(26,12): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(32,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalOrOperatorWithEveryType.ts(36,11): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(37,11): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(43,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalOrOperatorWithEveryType.ts(47,11): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(48,12): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(54,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalOrOperatorWithEveryType.ts(58,11): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(59,12): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(65,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalOrOperatorWithEveryType.ts(69,11): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(70,12): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(76,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalOrOperatorWithEveryType.ts(80,11): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(81,12): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(87,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalOrOperatorWithEveryType.ts(91,11): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(92,12): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(98,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalOrOperatorWithEveryType.ts(102,11): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(103,12): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(109,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalOrOperatorWithEveryType.ts(113,11): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(114,12): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(120,11): error TS1345: An expression of type 'void' cannot be tested for truthiness. +logicalOrOperatorWithEveryType.ts(124,11): error TS2873: This kind of expression is always falsy. logicalOrOperatorWithEveryType.ts(125,12): error TS2873: This kind of expression is always falsy. -==== logicalOrOperatorWithEveryType.ts (20 errors) ==== +==== logicalOrOperatorWithEveryType.ts (30 errors) ==== // The || operator permits the operands to be of any type. // If the || expression is not contextually typed, the right operand is contextually typed // by the type of the left operand and the result is of the best common type of the two @@ -48,6 +58,8 @@ logicalOrOperatorWithEveryType.ts(125,12): error TS2873: This kind of expression var ra7 = a7 || a1; // object || any is any var ra8 = a8 || a1; // array || any is any var ra9 = null || a1; // null || any is any + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var ra10 = undefined || a1; // undefined || any is any ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. @@ -63,6 +75,8 @@ logicalOrOperatorWithEveryType.ts(125,12): error TS2873: This kind of expression var rb7 = a7 || a2; // object || boolean is object | boolean var rb8 = a8 || a2; // array || boolean is array | boolean var rb9 = null || a2; // null || boolean is boolean + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var rb10= undefined || a2; // undefined || boolean is boolean ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. @@ -78,6 +92,8 @@ logicalOrOperatorWithEveryType.ts(125,12): error TS2873: This kind of expression var rc7 = a7 || a3; // object || number is object | number var rc8 = a8 || a3; // array || number is array | number var rc9 = null || a3; // null || number is number + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var rc10 = undefined || a3; // undefined || number is number ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. @@ -93,6 +109,8 @@ logicalOrOperatorWithEveryType.ts(125,12): error TS2873: This kind of expression var rd7 = a7 || a4; // object || string is object | string var rd8 = a8 || a4; // array || string is array | string var rd9 = null || a4; // null || string is string + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var rd10 = undefined || a4; // undefined || string is string ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. @@ -108,6 +126,8 @@ logicalOrOperatorWithEveryType.ts(125,12): error TS2873: This kind of expression var re7 = a7 || a5; // object || void is object | void var re8 = a8 || a5; // array || void is array | void var re9 = null || a5; // null || void is void + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var re10 = undefined || a5; // undefined || void is void ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. @@ -123,6 +143,8 @@ logicalOrOperatorWithEveryType.ts(125,12): error TS2873: This kind of expression var rg7 = a7 || a6; // object || enum is object | enum var rg8 = a8 || a6; // array || enum is array | enum var rg9 = null || a6; // null || enum is E + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var rg10 = undefined || a6; // undefined || enum is E ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. @@ -138,6 +160,8 @@ logicalOrOperatorWithEveryType.ts(125,12): error TS2873: This kind of expression var rh7 = a7 || a7; // object || object is object var rh8 = a8 || a7; // array || object is array | object var rh9 = null || a7; // null || object is object + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var rh10 = undefined || a7; // undefined || object is object ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. @@ -153,6 +177,8 @@ logicalOrOperatorWithEveryType.ts(125,12): error TS2873: This kind of expression var ri7 = a7 || a8; // object || array is object | array var ri8 = a8 || a8; // array || array is array var ri9 = null || a8; // null || array is array + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var ri10 = undefined || a8; // undefined || array is array ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. @@ -168,6 +194,8 @@ logicalOrOperatorWithEveryType.ts(125,12): error TS2873: This kind of expression var rj7 = a7 || null; // object || null is object var rj8 = a8 || null; // array || null is array var rj9 = null || null; // null || null is any + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var rj10 = undefined || null; // undefined || null is any ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. @@ -183,6 +211,8 @@ logicalOrOperatorWithEveryType.ts(125,12): error TS2873: This kind of expression var rf7 = a7 || undefined; // object || undefined is object var rf8 = a8 || undefined; // array || undefined is array var rf9 = null || undefined; // null || undefined is any + ~~~~ +!!! error TS2873: This kind of expression is always falsy. var rf10 = undefined || undefined; // undefined || undefined is any ~~~~~~~~~ !!! error TS2873: This kind of expression is always falsy. \ No newline at end of file diff --git a/tests/baselines/reference/voidAsOperator.errors.txt b/tests/baselines/reference/voidAsOperator.errors.txt index ac892e130cc97..c9a0fdf5bd303 100644 --- a/tests/baselines/reference/voidAsOperator.errors.txt +++ b/tests/baselines/reference/voidAsOperator.errors.txt @@ -1,7 +1,8 @@ voidAsOperator.ts(1,6): error TS2873: This kind of expression is always falsy. +voidAsOperator.ts(6,6): error TS2873: This kind of expression is always falsy. -==== voidAsOperator.ts (1 errors) ==== +==== voidAsOperator.ts (2 errors) ==== if (!void 0 !== true) { ~~~~~~ !!! error TS2873: This kind of expression is always falsy. @@ -10,6 +11,8 @@ voidAsOperator.ts(1,6): error TS2873: This kind of expression is always falsy. //CHECK#2 if (!null !== true) { + ~~~~ +!!! error TS2873: This kind of expression is always falsy. } \ No newline at end of file From 5f596248dcc4679de846bff0a3f69da43ce7edf0 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 22 Jul 2024 11:57:05 -0700 Subject: [PATCH 11/12] Add tests; just use skipOuterExpressions --- src/compiler/checker.ts | 10 ++---- .../reference/predicateSemantics.errors.txt | 20 +++++++++++- .../baselines/reference/predicateSemantics.js | 11 +++++++ .../reference/predicateSemantics.symbols | 6 ++++ .../reference/predicateSemantics.types | 31 +++++++++++++++++++ tests/cases/compiler/predicateSemantics.ts | 6 ++++ 6 files changed, 75 insertions(+), 9 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 33c78daede155..6a3f465bf6a5c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -39597,6 +39597,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function getSyntacticNullishnessSemantics(node: Node): PredicateSemantics { + node = skipOuterExpressions(node); switch (node.kind) { case SyntaxKind.AwaitExpression: case SyntaxKind.CallExpression: @@ -39619,10 +39620,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return PredicateSemantics.Sometimes; } return PredicateSemantics.Never; - case SyntaxKind.TypeAssertionExpression: - case SyntaxKind.AsExpression: - case SyntaxKind.ParenthesizedExpression: - return getSyntacticNullishnessSemantics((node as OuterExpression).expression); case SyntaxKind.ConditionalExpression: return getSyntacticNullishnessSemantics((node as ConditionalExpression).whenTrue) | getSyntacticNullishnessSemantics((node as ConditionalExpression).whenFalse); case SyntaxKind.NullKeyword: @@ -44284,6 +44281,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function getSyntacticTruthySemantics(node: Node): PredicateSemantics { + node = skipOuterExpressions(node); switch (node.kind) { case SyntaxKind.NumericLiteral: // Allow `while(0)` or `while(1)` @@ -44307,10 +44305,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { case SyntaxKind.NoSubstitutionTemplateLiteral: case SyntaxKind.StringLiteral: return !!(node as StringLiteral | NoSubstitutionTemplateLiteral).text ? PredicateSemantics.Always : PredicateSemantics.Never; - case SyntaxKind.TypeAssertionExpression: - case SyntaxKind.AsExpression: - case SyntaxKind.ParenthesizedExpression: - return getSyntacticTruthySemantics((node as OuterExpression).expression); case SyntaxKind.ConditionalExpression: return getSyntacticTruthySemantics((node as ConditionalExpression).whenTrue) | getSyntacticTruthySemantics((node as ConditionalExpression).whenFalse); case SyntaxKind.Identifier: diff --git a/tests/baselines/reference/predicateSemantics.errors.txt b/tests/baselines/reference/predicateSemantics.errors.txt index a02d2009f1b0b..4d96f98df22e5 100644 --- a/tests/baselines/reference/predicateSemantics.errors.txt +++ b/tests/baselines/reference/predicateSemantics.errors.txt @@ -5,9 +5,13 @@ predicateSemantics.ts(27,12): error TS2869: Right operand of ?? is unreachable b predicateSemantics.ts(28,12): error TS2871: This expression is always nullish. predicateSemantics.ts(29,12): error TS2872: This kind of expression is always truthy. predicateSemantics.ts(30,12): error TS2872: This kind of expression is always truthy. +predicateSemantics.ts(33,8): error TS2872: This kind of expression is always truthy. +predicateSemantics.ts(34,11): error TS2872: This kind of expression is always truthy. +predicateSemantics.ts(35,8): error TS2872: This kind of expression is always truthy. +predicateSemantics.ts(36,8): error TS2872: This kind of expression is always truthy. -==== predicateSemantics.ts (7 errors) ==== +==== predicateSemantics.ts (11 errors) ==== declare let cond: any; // OK: One or other operand is possibly nullish @@ -52,4 +56,18 @@ predicateSemantics.ts(30,12): error TS2872: This kind of expression is always tr const p9 = (class foo { }) || null; ~~~~~~~~~~~~~~~ !!! error TS2872: This kind of expression is always truthy. + + // Outer expression tests + while ({} as any) { } + ~~~~~~~~~ +!!! error TS2872: This kind of expression is always truthy. + while ({} satisfies unknown) { } + ~~~~~~~~~ +!!! error TS2872: This kind of expression is always truthy. + while ((({}))) { } + ~~~~~~~~~~~ +!!! error TS2872: This kind of expression is always truthy. + while ((({}))) { } + ~~~~~~ +!!! error TS2872: This kind of expression is always truthy. \ No newline at end of file diff --git a/tests/baselines/reference/predicateSemantics.js b/tests/baselines/reference/predicateSemantics.js index 0df3aea915e35..c1aebaad42b65 100644 --- a/tests/baselines/reference/predicateSemantics.js +++ b/tests/baselines/reference/predicateSemantics.js @@ -31,6 +31,12 @@ const p6 = 0 > 1 ?? null; const p7 = null ?? null; const p8 = (class foo { }) && null; const p9 = (class foo { }) || null; + +// Outer expression tests +while ({} as any) { } +while ({} satisfies unknown) { } +while ((({}))) { } +while ((({}))) { } //// [predicateSemantics.js] @@ -64,3 +70,8 @@ var p9 = (/** @class */ (function () { } return foo; }())) || null; +// Outer expression tests +while ({}) { } +while ({}) { } +while (({})) { } +while ((({}))) { } diff --git a/tests/baselines/reference/predicateSemantics.symbols b/tests/baselines/reference/predicateSemantics.symbols index 6881f89f06381..f92a128bbd48e 100644 --- a/tests/baselines/reference/predicateSemantics.symbols +++ b/tests/baselines/reference/predicateSemantics.symbols @@ -55,3 +55,9 @@ const p9 = (class foo { }) || null; >p9 : Symbol(p9, Decl(predicateSemantics.ts, 29, 5)) >foo : Symbol(foo, Decl(predicateSemantics.ts, 29, 12)) +// Outer expression tests +while ({} as any) { } +while ({} satisfies unknown) { } +while ((({}))) { } +while ((({}))) { } + diff --git a/tests/baselines/reference/predicateSemantics.types b/tests/baselines/reference/predicateSemantics.types index 3d8dab75361cd..b75183dc538bf 100644 --- a/tests/baselines/reference/predicateSemantics.types +++ b/tests/baselines/reference/predicateSemantics.types @@ -161,3 +161,34 @@ const p9 = (class foo { }) || null; >foo : typeof foo > : ^^^^^^^^^^ +// Outer expression tests +while ({} as any) { } +>{} as any : any +> : ^^^ +>{} : {} +> : ^^ + +while ({} satisfies unknown) { } +>{} satisfies unknown : {} +> : ^^ +>{} : {} +> : ^^ + +while ((({}))) { } +>(({})) : any +> : ^^^ +>({}) : any +> : ^^^ +>({}) : {} +> : ^^ +>{} : {} +> : ^^ + +while ((({}))) { } +>(({})) : {} +> : ^^ +>({}) : {} +> : ^^ +>{} : {} +> : ^^ + diff --git a/tests/cases/compiler/predicateSemantics.ts b/tests/cases/compiler/predicateSemantics.ts index 47ec505b23c39..4211a43ca5894 100644 --- a/tests/cases/compiler/predicateSemantics.ts +++ b/tests/cases/compiler/predicateSemantics.ts @@ -28,3 +28,9 @@ const p6 = 0 > 1 ?? null; const p7 = null ?? null; const p8 = (class foo { }) && null; const p9 = (class foo { }) || null; + +// Outer expression tests +while ({} as any) { } +while ({} satisfies unknown) { } +while ((({}))) { } +while ((({}))) { } From ba53157661e860fbe2029ab30f2d3be5d9f2f0df Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 22 Jul 2024 12:29:22 -0700 Subject: [PATCH 12/12] =?UTF-8?q?=F0=9F=A7=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/compiler/checker.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6a3f465bf6a5c..7a85c67d94391 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -915,7 +915,6 @@ import { OptionalTypeNode, or, orderedRemoveItemAt, - OuterExpression, OuterExpressionKinds, ParameterDeclaration, parameterIsThisKeyword,