@@ -24512,7 +24512,7 @@ namespace ts {
2451224512 // Grammar checking
2451324513 checkGrammarStatementInAmbientContext(node);
2451424514
24515- checkExpression (node.expression);
24515+ checkTruthinessExpression (node.expression);
2451624516 checkSourceElement(node.thenStatement);
2451724517
2451824518 if (node.thenStatement.kind === SyntaxKind.EmptyStatement) {
@@ -24527,17 +24527,25 @@ namespace ts {
2452724527 checkGrammarStatementInAmbientContext(node);
2452824528
2452924529 checkSourceElement(node.statement);
24530- checkExpression (node.expression);
24530+ checkTruthinessExpression (node.expression);
2453124531 }
2453224532
2453324533 function checkWhileStatement(node: WhileStatement) {
2453424534 // Grammar checking
2453524535 checkGrammarStatementInAmbientContext(node);
2453624536
24537- checkExpression (node.expression);
24537+ checkTruthinessExpression (node.expression);
2453824538 checkSourceElement(node.statement);
2453924539 }
2454024540
24541+ function checkTruthinessExpression(node: Expression) {
24542+ const type = checkExpression(node);
24543+ if (type === voidType) {
24544+ error(node, Diagnostics.An_expression_of_type_void_cannot_be_tested_for_truthiness);
24545+ }
24546+ return type;
24547+ }
24548+
2454124549 function checkForStatement(node: ForStatement) {
2454224550 // Grammar checking
2454324551 if (!checkGrammarStatementInAmbientContext(node)) {
@@ -24555,7 +24563,7 @@ namespace ts {
2455524563 }
2455624564 }
2455724565
24558- if (node.condition) checkExpression (node.condition);
24566+ if (node.condition) checkTruthinessExpression (node.condition);
2455924567 if (node.incrementor) checkExpression(node.incrementor);
2456024568 checkSourceElement(node.statement);
2456124569 if (node.locals) {
0 commit comments