@@ -574,18 +574,28 @@ namespace ts {
574574 function isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration: VariableDeclaration, usage: Node): boolean {
575575 const container = getEnclosingBlockScopeContainer(declaration);
576576
577- if (declaration.parent.parent.kind === SyntaxKind.VariableStatement ||
578- declaration.parent.parent.kind === SyntaxKind.ForStatement) {
579- // variable statement/for statement case,
580- // use site should not be inside variable declaration (initializer of declaration or binding element)
581- return isSameScopeDescendentOf(usage, declaration, container);
577+ switch (declaration.parent.parent.kind) {
578+ case SyntaxKind.VariableStatement:
579+ case SyntaxKind.ForStatement:
580+ case SyntaxKind.ForOfStatement:
581+ // variable statement/for/for-of statement case,
582+ // use site should not be inside variable declaration (initializer of declaration or binding element)
583+ if (isSameScopeDescendentOf(usage, declaration, container)) {
584+ return true;
585+ }
586+ break;
582587 }
583- else if (declaration.parent.parent.kind === SyntaxKind.ForOfStatement ||
584- declaration.parent.parent.kind === SyntaxKind.ForInStatement) {
585- // ForIn/ForOf case - use site should not be used in expression part
586- const expression = (<ForInStatement | ForOfStatement>declaration.parent.parent).expression;
587- return isSameScopeDescendentOf(usage, expression, container);
588+
589+ switch (declaration.parent.parent.kind) {
590+ case SyntaxKind.ForInStatement:
591+ case SyntaxKind.ForOfStatement:
592+ // ForIn/ForOf case - use site should not be used in expression part
593+ if (isSameScopeDescendentOf(usage, (<ForInStatement | ForOfStatement>declaration.parent.parent).expression, container)) {
594+ return true;
595+ }
588596 }
597+
598+ return false;
589599 }
590600
591601 function isUsedInFunctionOrNonStaticProperty(declaration: Declaration, usage: Node): boolean {
@@ -7989,7 +7999,7 @@ namespace ts {
79897999 const defaultsToDeclaredType = !strictNullChecks || type.flags & TypeFlags.Any || !declaration ||
79908000 getRootDeclaration(declaration).kind === SyntaxKind.Parameter || isInAmbientContext(declaration) ||
79918001 getContainingFunctionOrModule(declaration) !== getContainingFunctionOrModule(node);
7992- const flowType = getFlowTypeOfReference(node, type, defaultsToDeclaredType ? type : undefinedType );
8002+ const flowType = getFlowTypeOfReference(node, type, defaultsToDeclaredType ? type : addNullableKind(type, TypeFlags.Undefined) );
79938003 if (strictNullChecks && !(type.flags & TypeFlags.Any) && !(getNullableKind(type) & TypeFlags.Undefined) && getNullableKind(flowType) & TypeFlags.Undefined) {
79948004 error(node, Diagnostics.Variable_0_is_used_before_being_assigned, symbolToString(symbol));
79958005 // Return the declared type to reduce follow-on errors
0 commit comments