Skip to content

Commit adc8608

Browse files
committed
Initial type of variable is union of declared type and undefined
1 parent 4d53a21 commit adc8608

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7989,7 +7989,7 @@ namespace ts {
79897989
const defaultsToDeclaredType = !strictNullChecks || type.flags & TypeFlags.Any || !declaration ||
79907990
getRootDeclaration(declaration).kind === SyntaxKind.Parameter || isInAmbientContext(declaration) ||
79917991
getContainingFunctionOrModule(declaration) !== getContainingFunctionOrModule(node);
7992-
const flowType = getFlowTypeOfReference(node, type, defaultsToDeclaredType ? type : undefinedType);
7992+
const flowType = getFlowTypeOfReference(node, type, defaultsToDeclaredType ? type : addNullableKind(type, TypeFlags.Undefined));
79937993
if (strictNullChecks && !(type.flags & TypeFlags.Any) && !(getNullableKind(type) & TypeFlags.Undefined) && getNullableKind(flowType) & TypeFlags.Undefined) {
79947994
error(node, Diagnostics.Variable_0_is_used_before_being_assigned, symbolToString(symbol));
79957995
// Return the declared type to reduce follow-on errors

0 commit comments

Comments
 (0)