No excess property error for spread properties (#26798)

That is, properties in an object literal type that came from a spread
assignment never cause an excess property error.
This commit is contained in:
Nathan Shively-Sanders
2018-08-30 16:16:58 -07:00
committed by GitHub
parent cd37e41d3d
commit b687caf3eb
10 changed files with 67 additions and 157 deletions

View File

@@ -11328,7 +11328,7 @@ namespace ts {
return hasExcessProperties(source, discriminant, /*discriminant*/ undefined, reportErrors);
}
for (const prop of getPropertiesOfObjectType(source)) {
if (!isKnownProperty(target, prop.escapedName, isComparingJsxAttributes)) {
if (!isPropertyFromSpread(prop, source.symbol) && !isKnownProperty(target, prop.escapedName, isComparingJsxAttributes)) {
if (reportErrors) {
// We know *exactly* where things went wrong when comparing the types.
// Use this property as the error node as this will be more helpful in
@@ -11372,6 +11372,10 @@ namespace ts {
return false;
}
function isPropertyFromSpread(prop: Symbol, container: Symbol) {
return prop.valueDeclaration && container.valueDeclaration && prop.valueDeclaration.parent !== container.valueDeclaration;
}
function eachTypeRelatedToSomeType(source: UnionOrIntersectionType, target: UnionOrIntersectionType): Ternary {
let result = Ternary.True;
const sourceTypes = source.types;