File tree 1 file changed +3
-2
lines changed
1 file changed +3
-2
lines changed Original file line number Diff line number Diff line change @@ -4919,7 +4919,7 @@ namespace ts {
4919
4919
if (strictNullChecks && declaration.initializer && !(getFalsyFlags(checkDeclarationInitializer(declaration)) & TypeFlags.Undefined)) {
4920
4920
type = getTypeWithFacts(type, TypeFacts.NEUndefined);
4921
4921
}
4922
- return declaration.initializer && !getContextualTypeForVariableLikeDeclaration (walkUpBindingElementsAndPatterns(declaration)) ?
4922
+ return declaration.initializer && !getEffectiveTypeAnnotationNode (walkUpBindingElementsAndPatterns(declaration)) ?
4923
4923
getUnionType([type, checkDeclarationInitializer(declaration)], UnionReduction.Subtype) :
4924
4924
type;
4925
4925
}
@@ -22810,7 +22810,8 @@ namespace ts {
22810
22810
const type = getTypeOfExpression(initializer, /*cache*/ true);
22811
22811
const widened = getCombinedNodeFlags(declaration) & NodeFlags.Const ||
22812
22812
isDeclarationReadonly(declaration) ||
22813
- isTypeAssertion(initializer) ? type : getWidenedLiteralType(type);
22813
+ isTypeAssertion(initializer) ||
22814
+ isLiteralOfContextualType(type, getContextualType(initializer)) ? type : getWidenedLiteralType(type);
22814
22815
if (isInJSFile(declaration)) {
22815
22816
if (widened.flags & TypeFlags.Nullable) {
22816
22817
reportImplicitAny(declaration, anyType);
You can’t perform that action at this time.
0 commit comments