Skip to content

Commit deb87bb

Browse files
committed
Obtain constraint from destructured property when applicable
1 parent 02ee11c commit deb87bb

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/compiler/checker.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -4082,8 +4082,7 @@ namespace ts {
40824082
if (strictNullChecks && declaration.flags & NodeFlags.Ambient && isParameterDeclaration(declaration)) {
40834083
parentType = getNonNullableType(parentType);
40844084
}
4085-
const propType = getTypeOfPropertyOfType(parentType, text);
4086-
const declaredType = propType && getConstraintForLocation(propType, declaration.name);
4085+
const declaredType = getConstraintForLocation(getTypeOfPropertyOfType(parentType, text), declaration.name);
40874086
type = declaredType && getFlowTypeOfReference(declaration, declaredType) ||
40884087
isNumericLiteralName(text) && getIndexTypeOfType(parentType, IndexKind.Number) ||
40894088
getIndexTypeOfType(parentType, IndexKind.String);
@@ -12382,7 +12381,7 @@ namespace ts {
1238212381

1238312382
function getTypeOfDestructuredProperty(type: Type, name: PropertyName) {
1238412383
const text = getTextOfPropertyName(name);
12385-
return getTypeOfPropertyOfType(type, text) ||
12384+
return getConstraintForLocation(getTypeOfPropertyOfType(type, text), name) ||
1238612385
isNumericLiteralName(text) && getIndexTypeOfType(type, IndexKind.Number) ||
1238712386
getIndexTypeOfType(type, IndexKind.String) ||
1238812387
unknownType;
@@ -13498,7 +13497,7 @@ namespace ts {
1349813497
// and the type of the node includes type variables with constraints that are nullable, we fetch the
1349913498
// apparent type of the node *before* performing control flow analysis such that narrowings apply to
1350013499
// the constraint type.
13501-
if (isConstraintPosition(node) && forEachType(type, typeHasNullableConstraint)) {
13500+
if (type && isConstraintPosition(node) && forEachType(type, typeHasNullableConstraint)) {
1350213501
return mapType(getWidenedType(type), getBaseConstraintOrType);
1350313502
}
1350413503
return type;

0 commit comments

Comments
 (0)