Skip to content

Commit 1ff6007

Browse files
committed
unknownify accesses
1 parent 32e99ba commit 1ff6007

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/compiler/checker.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9124,7 +9124,7 @@ namespace ts {
91249124
markPropertyAsReferenced(prop, accessExpression, /*isThisAccess*/ accessExpression.expression.kind === SyntaxKind.ThisKeyword);
91259125
if (isAssignmentTarget(accessExpression) && (isReferenceToReadonlyEntity(accessExpression, prop) || isReferenceThroughNamespaceImport(accessExpression))) {
91269126
error(accessExpression.argumentExpression, Diagnostics.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, symbolToString(prop));
9127-
return errorType;
9127+
return accessNode ? errorType : unknownType;
91289128
}
91299129
if (cacheSymbol) {
91309130
getNodeLinks(accessNode!).resolvedSymbol = prop;
@@ -9182,7 +9182,7 @@ namespace ts {
91829182
}
91839183
}
91849184
}
9185-
return anyType;
9185+
return accessNode ? errorType : unknownType;
91869186
}
91879187
}
91889188
if (isJSLiteralType(objectType)) {
@@ -9200,7 +9200,7 @@ namespace ts {
92009200
error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeToString(indexType));
92019201
}
92029202
}
9203-
return errorType;
9203+
return accessNode ? errorType : unknownType;
92049204
}
92059205

92069206
function isGenericObjectType(type: Type): boolean {
@@ -9297,6 +9297,12 @@ namespace ts {
92979297
if (objectType === wildcardType || indexType === wildcardType) {
92989298
return wildcardType;
92999299
}
9300+
if (objectType.flags & TypeFlags.Union) {
9301+
return mapType(objectType, t => getIndexedAccessType(t, indexType));
9302+
}
9303+
if (objectType.flags & TypeFlags.Intersection) {
9304+
return getIntersectionType(map((objectType as IntersectionType).types, t => getIndexedAccessType(t, indexType)));
9305+
}
93009306
// If the index type is generic, or if the object type is generic and doesn't originate in an expression,
93019307
// we are performing a higher-order index access where we cannot meaningfully access the properties of the
93029308
// object type. Note that for a generic T and a non-generic K, we eagerly resolve T[K] if it originates in
@@ -9322,6 +9328,9 @@ namespace ts {
93229328
const propTypes: Type[] = [];
93239329
for (const t of (<UnionType>indexType).types) {
93249330
const propType = getPropertyTypeForIndexType(apparentObjectType, t, accessNode, /*cacheSymbol*/ false);
9331+
if (propType === unknownType) {
9332+
return unknownType;
9333+
}
93259334
if (propType === errorType) {
93269335
return errorType;
93279336
}

0 commit comments

Comments
 (0)