@@ -19518,6 +19518,21 @@ namespace ts {
19518
19518
return type;
19519
19519
}
19520
19520
19521
+ function checkNonNullNonVoidType(
19522
+ type: Type,
19523
+ node: Node,
19524
+ nullDiagnostic?: DiagnosticMessage,
19525
+ undefinedDiagnostic?: DiagnosticMessage,
19526
+ nullOrUndefinedDiagnostic?: DiagnosticMessage,
19527
+ voidDiagnostic?: DiagnosticMessage
19528
+ ): Type {
19529
+ const nonNullType = checkNonNullType(type, node, nullDiagnostic, undefinedDiagnostic, nullOrUndefinedDiagnostic);
19530
+ if (nonNullType !== errorType && nonNullType.flags & TypeFlags.Void) {
19531
+ error(node, voidDiagnostic || Diagnostics.Object_is_possibly_undefined);
19532
+ }
19533
+ return nonNullType;
19534
+ }
19535
+
19521
19536
function checkPropertyAccessExpression(node: PropertyAccessExpression) {
19522
19537
return checkPropertyAccessExpressionOrQualifiedName(node, node.expression, node.name);
19523
19538
}
@@ -26258,7 +26273,7 @@ namespace ts {
26258
26273
if (node.initializer && node.parent.parent.kind !== SyntaxKind.ForInStatement) {
26259
26274
const initializerType = checkExpressionCached(node.initializer);
26260
26275
if (strictNullChecks && node.name.elements.length === 0) {
26261
- checkNonNullType (initializerType, node);
26276
+ checkNonNullNonVoidType (initializerType, node);
26262
26277
}
26263
26278
else {
26264
26279
checkTypeAssignableToAndOptionallyElaborate(initializerType, getWidenedTypeForVariableLikeDeclaration(node), node, node.initializer);
0 commit comments