Skip to content

Commit 6d8950e

Browse files
committed
Fix check for excess properties in union and intersection types
1 parent 1b36407 commit 6d8950e

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/compiler/checker.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4946,34 +4946,34 @@ namespace ts {
49464946
resolved.stringIndexType || resolved.numberIndexType || getPropertyOfType(type, name)) {
49474947
return true;
49484948
}
4949-
return false;
49504949
}
4951-
if (type.flags & TypeFlags.UnionOrIntersection) {
4950+
else if (type.flags & TypeFlags.UnionOrIntersection) {
49524951
for (let t of (<UnionOrIntersectionType>type).types) {
49534952
if (isKnownProperty(t, name)) {
49544953
return true;
49554954
}
49564955
}
4957-
return false;
49584956
}
4959-
return true;
4957+
return false;
49604958
}
49614959

49624960
function hasExcessProperties(source: FreshObjectLiteralType, target: Type, reportErrors: boolean): boolean {
4963-
for (let prop of getPropertiesOfObjectType(source)) {
4964-
if (!isKnownProperty(target, prop.name)) {
4965-
if (reportErrors) {
4966-
// We know *exactly* where things went wrong when comparing the types.
4967-
// Use this property as the error node as this will be more helpful in
4968-
// reasoning about what went wrong.
4969-
errorNode = prop.valueDeclaration;
4970-
reportError(Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1,
4971-
symbolToString(prop),
4972-
typeToString(target));
4961+
if (someConstituentTypeHasKind(target, TypeFlags.ObjectType)) {
4962+
for (let prop of getPropertiesOfObjectType(source)) {
4963+
if (!isKnownProperty(target, prop.name)) {
4964+
if (reportErrors) {
4965+
// We know *exactly* where things went wrong when comparing the types.
4966+
// Use this property as the error node as this will be more helpful in
4967+
// reasoning about what went wrong.
4968+
errorNode = prop.valueDeclaration;
4969+
reportError(Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1,
4970+
symbolToString(prop), typeToString(target));
4971+
}
4972+
return true;
49734973
}
4974-
return true;
49754974
}
49764975
}
4976+
return false;
49774977
}
49784978

49794979
function eachTypeRelatedToSomeType(source: UnionOrIntersectionType, target: UnionOrIntersectionType): Ternary {

0 commit comments

Comments
 (0)