@@ -9124,7 +9124,7 @@ namespace ts {
9124
9124
markPropertyAsReferenced(prop, accessExpression, /*isThisAccess*/ accessExpression.expression.kind === SyntaxKind.ThisKeyword);
9125
9125
if (isAssignmentTarget(accessExpression) && (isReferenceToReadonlyEntity(accessExpression, prop) || isReferenceThroughNamespaceImport(accessExpression))) {
9126
9126
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 ;
9128
9128
}
9129
9129
if (cacheSymbol) {
9130
9130
getNodeLinks(accessNode!).resolvedSymbol = prop;
@@ -9182,7 +9182,7 @@ namespace ts {
9182
9182
}
9183
9183
}
9184
9184
}
9185
- return anyType ;
9185
+ return accessNode ? errorType : unknownType ;
9186
9186
}
9187
9187
}
9188
9188
if (isJSLiteralType(objectType)) {
@@ -9200,7 +9200,7 @@ namespace ts {
9200
9200
error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeToString(indexType));
9201
9201
}
9202
9202
}
9203
- return errorType;
9203
+ return accessNode ? errorType : unknownType ;
9204
9204
}
9205
9205
9206
9206
function isGenericObjectType(type: Type): boolean {
@@ -9297,6 +9297,12 @@ namespace ts {
9297
9297
if (objectType === wildcardType || indexType === wildcardType) {
9298
9298
return wildcardType;
9299
9299
}
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
+ }
9300
9306
// If the index type is generic, or if the object type is generic and doesn't originate in an expression,
9301
9307
// we are performing a higher-order index access where we cannot meaningfully access the properties of the
9302
9308
// 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 {
9322
9328
const propTypes: Type[] = [];
9323
9329
for (const t of (<UnionType>indexType).types) {
9324
9330
const propType = getPropertyTypeForIndexType(apparentObjectType, t, accessNode, /*cacheSymbol*/ false);
9331
+ if (propType === unknownType) {
9332
+ return unknownType;
9333
+ }
9325
9334
if (propType === errorType) {
9326
9335
return errorType;
9327
9336
}
0 commit comments