@@ -16031,11 +16031,6 @@ namespace ts {
16031
16031
return related;
16032
16032
}
16033
16033
16034
- function hasIndexInfo(type: Type, kind: IndexKind): boolean {
16035
- return type.flags & TypeFlags.Intersection ? every((<IntersectionType>type).types, t => hasIndexInfo(t, kind)) :
16036
- !!(getIndexInfoOfType(type, kind) || kind === IndexKind.Number && getIndexInfoOfType(type, IndexKind.String) || isObjectTypeWithInferableIndex(type));
16037
- }
16038
-
16039
16034
function indexTypesRelatedTo(source: Type, target: Type, kind: IndexKind, sourceIsPrimitive: boolean, reportErrors: boolean): Ternary {
16040
16035
if (relation === identityRelation) {
16041
16036
return indexTypesIdenticalTo(source, target, kind);
@@ -16050,24 +16045,24 @@ namespace ts {
16050
16045
// if T is related to U.
16051
16046
return kind === IndexKind.String ? isRelatedTo(getTemplateTypeFromMappedType(source), targetType, reportErrors) : Ternary.False;
16052
16047
}
16053
- if (!hasIndexInfo(source, kind)) {
16054
- if (reportErrors) {
16055
- reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source));
16056
- }
16057
- return Ternary.False;
16058
- }
16059
16048
const indexType = getIndexTypeOfType(source, kind) || kind === IndexKind.Number && getIndexTypeOfType(source, IndexKind.String);
16060
16049
if (indexType) {
16061
16050
return indexTypeRelatedTo(indexType, targetType, reportErrors);
16062
16051
}
16063
- let related = eachPropertyRelatedTo(source, targetType, kind, reportErrors);
16064
- if (related && kind === IndexKind.String) {
16065
- const numberIndexType = getIndexTypeOfType(source, IndexKind.Number);
16066
- if (numberIndexType) {
16067
- related &= indexTypeRelatedTo(numberIndexType, targetType, reportErrors);
16052
+ if (isObjectTypeWithInferableIndex(source)) {
16053
+ let related = eachPropertyRelatedTo(source, targetType, kind, reportErrors);
16054
+ if (related && kind === IndexKind.String) {
16055
+ const numberIndexType = getIndexTypeOfType(source, IndexKind.Number);
16056
+ if (numberIndexType) {
16057
+ related &= indexTypeRelatedTo(numberIndexType, targetType, reportErrors);
16058
+ }
16068
16059
}
16060
+ return related;
16069
16061
}
16070
- return related;
16062
+ if (reportErrors) {
16063
+ reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source));
16064
+ }
16065
+ return Ternary.False;
16071
16066
}
16072
16067
16073
16068
function indexTypesIdenticalTo(source: Type, target: Type, indexKind: IndexKind): Ternary {
@@ -16820,7 +16815,8 @@ namespace ts {
16820
16815
* with no call or construct signatures.
16821
16816
*/
16822
16817
function isObjectTypeWithInferableIndex(type: Type): boolean {
16823
- return !!(type.symbol && (type.symbol.flags & (SymbolFlags.ObjectLiteral | SymbolFlags.TypeLiteral | SymbolFlags.Enum | SymbolFlags.ValueModule)) !== 0 &&
16818
+ return type.flags & TypeFlags.Intersection ? every((<IntersectionType>type).types, isObjectTypeWithInferableIndex) :
16819
+ !!(type.symbol && (type.symbol.flags & (SymbolFlags.ObjectLiteral | SymbolFlags.TypeLiteral | SymbolFlags.Enum | SymbolFlags.ValueModule)) !== 0 &&
16824
16820
!typeHasCallOrConstructSignatures(type)) || !!(getObjectFlags(type) & ObjectFlags.ReverseMapped && isObjectTypeWithInferableIndex((type as ReverseMappedType).source));
16825
16821
}
16826
16822
0 commit comments