Skip to content

Commit 959c3aa

Browse files
committed
Fix excess property checking for intersections with index signatures
1 parent eb9252e commit 959c3aa

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20693,6 +20693,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2069320693
isNonGenericObjectType(target) && !isArrayOrTupleType(target) && source.flags & TypeFlags.Intersection && getApparentType(source).flags & TypeFlags.StructuredType && !some((source as IntersectionType).types, t => !!(getObjectFlags(t) & ObjectFlags.NonInferrableType)))) {
2069420694
inPropertyCheck = true;
2069520695
result &= propertiesRelatedTo(source, target, reportErrors, /*excludedProperties*/ undefined, IntersectionState.None);
20696+
if (result) {
20697+
result &= indexSignaturesRelatedTo(source, target, /*sourceIsPrimitive*/ false, reportErrors, IntersectionState.None);
20698+
}
2069620699
inPropertyCheck = false;
2069720700
}
2069820701
}
@@ -21861,7 +21864,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2186121864
return result;
2186221865
}
2186321866

21864-
function membersRelatedToIndexInfo(source: Type, targetInfo: IndexInfo, reportErrors: boolean): Ternary {
21867+
function membersRelatedToIndexInfo(source: Type, targetInfo: IndexInfo, reportErrors: boolean, intersectionState: IntersectionState): Ternary {
2186521868
let result = Ternary.True;
2186621869
const keyType = targetInfo.keyType;
2186721870
const props = source.flags & TypeFlags.Intersection ? getPropertiesOfUnionOrIntersectionType(source as IntersectionType) : getPropertiesOfObjectType(source);
@@ -21875,7 +21878,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2187521878
const type = exactOptionalPropertyTypes || propType.flags & TypeFlags.Undefined || keyType === numberType || !(prop.flags & SymbolFlags.Optional)
2187621879
? propType
2187721880
: getTypeWithFacts(propType, TypeFacts.NEUndefined);
21878-
const related = isRelatedTo(type, targetInfo.type, RecursionFlags.Both, reportErrors);
21881+
const related = isRelatedTo(type, targetInfo.type, RecursionFlags.Both, reportErrors, /*headMessage*/ undefined, intersectionState);
2187921882
if (!related) {
2188021883
if (reportErrors) {
2188121884
reportError(Diagnostics.Property_0_is_incompatible_with_index_signature, symbolToString(prop));
@@ -21936,7 +21939,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2193621939
}
2193721940
if (!(intersectionState & IntersectionState.Source) && isObjectTypeWithInferableIndex(source)) {
2193821941
// Intersection constituents are never considered to have an inferred index signature
21939-
return membersRelatedToIndexInfo(source, targetInfo, reportErrors);
21942+
return membersRelatedToIndexInfo(source, targetInfo, reportErrors, intersectionState);
2194021943
}
2194121944
if (reportErrors) {
2194221945
reportError(Diagnostics.Index_signature_for_type_0_is_missing_in_type_1, typeToString(targetInfo.keyType), typeToString(source));

0 commit comments

Comments
 (0)