File tree 1 file changed +6
-5
lines changed
1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -11717,17 +11717,18 @@ namespace ts {
11717
11717
parent.kind === SyntaxKind.ElementAccessExpression && (<ElementAccessExpression>parent).expression === node;
11718
11718
}
11719
11719
11720
+ function typeHasNullableConstraint(type: Type) {
11721
+ return type.flags & TypeFlags.TypeVariable && maybeTypeOfKind(getBaseConstraintOfType(type) || emptyObjectType, TypeFlags.Nullable);
11722
+ }
11723
+
11720
11724
function getDeclaredOrApparentType(symbol: Symbol, node: Node) {
11721
11725
// When a node is the left hand expression of a property access, element access, or call expression,
11722
11726
// and the type of the node includes type variables with constraints that are nullable, we fetch the
11723
11727
// apparent type of the node *before* performing control flow analysis such that narrowings apply to
11724
11728
// the constraint type.
11725
11729
const type = getTypeOfSymbol(symbol);
11726
- if (isApparentTypePosition(node) && maybeTypeOfKind(type, TypeFlags.TypeVariable)) {
11727
- const apparentType = mapType(getWidenedType(type), getApparentType);
11728
- if (maybeTypeOfKind(apparentType, TypeFlags.Nullable)) {
11729
- return apparentType;
11730
- }
11730
+ if (isApparentTypePosition(node) && forEachType(type, typeHasNullableConstraint)) {
11731
+ return mapType(getWidenedType(type), getApparentType);
11731
11732
}
11732
11733
return type;
11733
11734
}
You can’t perform that action at this time.
0 commit comments