Skip to content

Commit 3d069f7

Browse files
committed
New behavior only for type variables with nullable constraints
1 parent 3448164 commit 3d069f7

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11711,21 +11711,21 @@ namespace ts {
1171111711
}
1171211712

1171311713
function isApparentTypePosition(node: Node) {
11714-
// When a node is the left hand expression of a property access or call expression, the node occurs
11715-
// in an apparent type position. In such a position we fetch the apparent type of the node *before*
11716-
// performing control flow analysis such that, if the node is a type variable, we apply narrowings
11717-
// to the constraint type.
1171811714
const parent = node.parent;
1171911715
return parent.kind === SyntaxKind.PropertyAccessExpression ||
1172011716
parent.kind === SyntaxKind.CallExpression && (<CallExpression>parent).expression === node ||
1172111717
parent.kind === SyntaxKind.ElementAccessExpression && (<ElementAccessExpression>parent).expression === node;
1172211718
}
1172311719

1172411720
function getDeclaredOrApparentType(symbol: Symbol, node: Node) {
11721+
// When a node is the left hand expression of a property access, element access, or call expression,
11722+
// and the type of the node includes type variables with constraints that are nullable, we fetch the
11723+
// apparent type of the node *before* performing control flow analysis such that narrowings apply to
11724+
// the constraint type.
1172511725
const type = getTypeOfSymbol(symbol);
1172611726
if (isApparentTypePosition(node) && maybeTypeOfKind(type, TypeFlags.TypeVariable)) {
1172711727
const apparentType = mapType(getWidenedType(type), getApparentType);
11728-
if (apparentType !== emptyObjectType) {
11728+
if (maybeTypeOfKind(apparentType, TypeFlags.Nullable)) {
1172911729
return apparentType;
1173011730
}
1173111731
}

0 commit comments

Comments
 (0)