-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Master] fix 15463 #15595
[Master] fix 15463 #15595
Conversation
…icitly specified attributes are correct
src/compiler/checker.ts
Outdated
@@ -13351,7 +13356,8 @@ namespace ts { | |||
*/ | |||
function createJsxAttributesType(symbol: Symbol, attributesTable: Map<Symbol>) { | |||
const result = createAnonymousType(symbol, attributesTable, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined); | |||
const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshLiteral; | |||
// Spread object doesn't have freshness flag to allow excess attributes as it is very common for parent component to spread its "props" to other components in its render method. | |||
const freshObjectLiteralFlag = spread !== emptyObjectType || compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshLiteral; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so why do we have this flag, should not the check below catch all the cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes but I don't think we should do for all explicitly defined. since that case you should cover by type assignability check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure i understand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
talk offline with @mhegazy it is being too clever and doing second pass isn't expensive so we should remove this flag and always check for that explicit property has correct name
src/compiler/checker.ts
Outdated
if (sourceAttributesType !== anyType && !(sourceAttributesType.flags & TypeFlags.FreshLiteral)) { | ||
for (const attribute of openingLikeElement.attributes.properties) { | ||
if (isJsxAttribute(attribute) && !getPropertyOfType(targetAttributesType, attribute.name.text)) { | ||
error(attribute, Diagnostics.Property_0_does_not_exist_on_type_1, attribute.name.text, typeToString(targetAttributesType)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would break after the first error to avoid cascading errors.
Fix #15463 We are now checking attributes according to:
Only contain explicitly attributes -> no excess properties allowed
Contain spread attributes (even with explicit attributes) -> 1. check type assignability (allow access properties) 2. for each explicit attributes check if the attribute name match the target name.
we only report that "children" will get overwritten if it is explicitly specified in the attributes and the element contains JSX.children