Skip to content

Commit 5933dd0

Browse files
committed
Fix minor style nits
1 parent 4e9d35b commit 5933dd0

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/compiler/checker.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8884,6 +8884,10 @@ namespace ts {
88848884
return false;
88858885
}
88868886

8887+
function isIgnoredJsxProperty(source: Type, sourceProp: Symbol, targetMemberType: Type | undefined) {
8888+
return source.flags & TypeFlags.JsxAttributes && !(isUnhyphenatedJsxName(sourceProp.escapedName) || targetMemberType);
8889+
}
8890+
88878891
/**
88888892
* Checks if 'source' is related to 'target' (e.g.: is a assignable to).
88898893
* @param source The left-hand-side of the relation.
@@ -9580,10 +9584,6 @@ namespace ts {
95809584
return Ternary.False;
95819585
}
95829586

9583-
function isIgnoredJsxProperty(source: Type, sourceProp: Symbol, targetMemberType: Type | undefined) {
9584-
return source.flags & TypeFlags.JsxAttributes && !(isUnhyphenatedJsxName(sourceProp.escapedName) || !!targetMemberType);
9585-
}
9586-
95879587
function propertiesRelatedTo(source: Type, target: Type, reportErrors: boolean): Ternary {
95889588
if (relation === identityRelation) {
95899589
return propertiesIdenticalTo(source, target);
@@ -14200,7 +14200,7 @@ namespace ts {
1420014200
if (hasSpreadAnyType) {
1420114201
return anyType;
1420214202
}
14203-
return typeToIntersect ? getIntersectionType([typeToIntersect, ...spread === emptyObjectType ? [] : [spread]]) : spread;
14203+
return typeToIntersect && spread !== emptyObjectType ? getIntersectionType([typeToIntersect, spread]) : (typeToIntersect || spread);
1420414204

1420514205
/**
1420614206
* Create anonymous type from given attributes symbol table.
@@ -14810,11 +14810,16 @@ namespace ts {
1481014810
// Check if sourceAttributesType assignable to targetAttributesType though this check will allow excess properties
1481114811
const isSourceAttributeTypeAssignableToTarget = checkTypeAssignableTo(sourceAttributesType, targetAttributesType, openingLikeElement.attributes.properties.length > 0 ? openingLikeElement.attributes : openingLikeElement);
1481214812
// After we check for assignability, we will do another pass to check that all explicitly specified attributes have correct name corresponding in targetAttributeType.
14813-
// This will allow excess properties in spread type as it is very common pattern to spread outter attributes into React component in its render method.
14813+
// This will allow excess properties in spread type as it is very common pattern to spread outer attributes into React component in its render method.
1481414814
if (isSourceAttributeTypeAssignableToTarget && !isTypeAny(sourceAttributesType) && !isTypeAny(targetAttributesType)) {
1481514815
for (const attribute of openingLikeElement.attributes.properties) {
14816-
if (isJsxAttribute(attribute) && (isUnhyphenatedJsxName(idText(attribute.name)) || !!(getPropertyOfType(targetAttributesType, attribute.name.escapedText))) && !isKnownProperty(targetAttributesType, attribute.name.escapedText, /*isComparingJsxAttributes*/ true)) {
14817-
error(attribute, Diagnostics.Property_0_does_not_exist_on_type_1, idText(attribute.name), typeToString(targetAttributesType));
14816+
if (!isJsxAttribute(attribute)) {
14817+
continue;
14818+
}
14819+
const attrName = attribute.name as Identifier;
14820+
const isNotIgnoredJsxProperty = (isUnhyphenatedJsxName(idText(attrName)) || !!(getPropertyOfType(targetAttributesType, attrName.escapedText)));
14821+
if (isNotIgnoredJsxProperty && !isKnownProperty(targetAttributesType, attrName.escapedText, /*isComparingJsxAttributes*/ true)) {
14822+
error(attribute, Diagnostics.Property_0_does_not_exist_on_type_1, idText(attrName), typeToString(targetAttributesType));
1481814823
// We break here so that errors won't be cascading
1481914824
break;
1482014825
}
@@ -15720,7 +15725,7 @@ namespace ts {
1572015725
// However "context" and "updater" are implicit and can't be specify by users. Only the first parameter, props,
1572115726
// can be specified by users through attributes property.
1572215727
const paramType = getTypeAtPosition(signature, 0);
15723-
const attributesType = checkExpressionWithContextualType(node.attributes, paramType, /* contextualMapper */ undefined);
15728+
const attributesType = checkExpressionWithContextualType(node.attributes, paramType, /*contextualMapper*/ undefined);
1572415729
const argProperties = getPropertiesOfType(attributesType);
1572515730
for (const arg of argProperties) {
1572615731
if (!getPropertyOfType(paramType, arg.escapedName) && isUnhyphenatedJsxName(arg.escapedName)) {

0 commit comments

Comments
 (0)