File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -10145,6 +10145,11 @@ namespace ts {
10145
10145
if (objectType === wildcardType || indexType === wildcardType) {
10146
10146
return wildcardType;
10147
10147
}
10148
+ // If the object type has a string index signature and no other members we know that the result will
10149
+ // always be the type of that index signature and we can simplify accordingly.
10150
+ if (isStringIndexSignatureOnlyType(objectType) && !(indexType.flags & TypeFlags.Nullable) && isTypeAssignableToKind(indexType, TypeFlags.String | TypeFlags.Number)) {
10151
+ indexType = stringType;
10152
+ }
10148
10153
// If the index type is generic, or if the object type is generic and doesn't originate in an expression,
10149
10154
// we are performing a higher-order index access where we cannot meaningfully access the properties of the
10150
10155
// object type. Note that for a generic T and a non-generic K, we eagerly resolve T[K] if it originates in
@@ -12022,6 +12027,12 @@ namespace ts {
12022
12027
return !!(getObjectFlags(type) & ObjectFlags.Anonymous) && isEmptyObjectType(type);
12023
12028
}
12024
12029
12030
+ function isStringIndexSignatureOnlyType(type: Type): boolean {
12031
+ return type.flags & TypeFlags.Object && getPropertiesOfType(type).length === 0 && getIndexInfoOfType(type, IndexKind.String) && !getIndexInfoOfType(type, IndexKind.Number) ||
12032
+ type.flags & TypeFlags.UnionOrIntersection && every((<UnionOrIntersectionType>type).types, isStringIndexSignatureOnlyType) ||
12033
+ false;
12034
+ }
12035
+
12025
12036
function isEnumTypeRelatedTo(sourceSymbol: Symbol, targetSymbol: Symbol, errorReporter?: ErrorReporter) {
12026
12037
if (sourceSymbol === targetSymbol) {
12027
12038
return true;
You can’t perform that action at this time.
0 commit comments