Skip to content

Commit a25104e

Browse files
committed
Use union type when binding element has initializer
1 parent 598ca48 commit a25104e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2974,7 +2974,9 @@ namespace ts {
29742974
if (strictNullChecks && declaration.initializer && !(getFalsyFlags(checkExpressionCached(declaration.initializer)) & TypeFlags.Undefined)) {
29752975
type = getTypeWithFacts(type, TypeFacts.NEUndefined);
29762976
}
2977-
return type;
2977+
return declaration.initializer ?
2978+
getUnionType([type, checkExpressionCached(declaration.initializer)], /*subtypeReduction*/ true) :
2979+
type;
29782980
}
29792981

29802982
function getTypeForVariableLikeDeclarationFromJSDocComment(declaration: VariableLikeDeclaration) {

0 commit comments

Comments
 (0)