Skip to content

Commit bb8bab3

Browse files
author
Kanchalai Tanglertsampan
committed
Remove a flag indicating the children is synthesized..We will give an error if you use children without specified such property
1 parent 58e2189 commit bb8bab3

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8650,7 +8650,7 @@ namespace ts {
86508650
// is considered known if the object type is empty and the check is for assignability, if the object type has
86518651
// index signatures, or if the property is actually declared in the object type. In a union or intersection
86528652
// type, a property is considered known if it is known in any constituent type.
8653-
function isKnownProperty(type: Type, name: string, isComparingJsxAttributes: boolean, containsSynthesizedJsxChildren: boolean): boolean {
8653+
function isKnownProperty(type: Type, name: string, isComparingJsxAttributes: boolean): boolean {
86548654
if (type.flags & TypeFlags.Object) {
86558655
const resolved = resolveStructuredTypeMembers(<ObjectType>type);
86568656
if ((relation === assignableRelation || relation === comparableRelation) &&
@@ -8660,16 +8660,14 @@ namespace ts {
86608660
else if (resolved.stringIndexInfo || (resolved.numberIndexInfo && isNumericLiteralName(name))) {
86618661
return true;
86628662
}
8663-
else if (getPropertyOfType(type, name) || containsSynthesizedJsxChildren || (isComparingJsxAttributes && !isUnhyphenatedJsxName(name))) {
8664-
// For JSXAttributes, consider that the attribute to be known if
8665-
// 1. the attribute has a hyphenated name
8666-
// 2. "children" attribute that is synthesized from children property of Jsx element
8663+
else if (getPropertyOfType(type, name) || (isComparingJsxAttributes && !isUnhyphenatedJsxName(name))) {
8664+
// For JSXAttributes, consider that the attribute to be known if the attribute has a hyphenated name
86678665
return true;
86688666
}
86698667
}
86708668
else if (type.flags & TypeFlags.UnionOrIntersection) {
86718669
for (const t of (<UnionOrIntersectionType>type).types) {
8672-
if (isKnownProperty(t, name, isComparingJsxAttributes, containsSynthesizedJsxChildren)) {
8670+
if (isKnownProperty(t, name, isComparingJsxAttributes)) {
86738671
return true;
86748672
}
86758673
}
@@ -8680,15 +8678,14 @@ namespace ts {
86808678
function hasExcessProperties(source: FreshObjectLiteralType, target: Type, reportErrors: boolean): boolean {
86818679
if (maybeTypeOfKind(target, TypeFlags.Object) && !(getObjectFlags(target) & ObjectFlags.ObjectLiteralPatternWithComputedProperties)) {
86828680
const isComparingJsxAttributes = !!(source.flags & TypeFlags.JsxAttributes);
8683-
const containsSynthesizedJsxChildren = !!(source.flags & TypeFlags.ContainsSynthesizedJsxChildren);
86848681
for (const prop of getPropertiesOfObjectType(source)) {
8685-
if (!isKnownProperty(target, prop.name, isComparingJsxAttributes, containsSynthesizedJsxChildren)) {
8682+
if (!isKnownProperty(target, prop.name, isComparingJsxAttributes)) {
86868683
if (reportErrors) {
86878684
// We know *exactly* where things went wrong when comparing the types.
86888685
// Use this property as the error node as this will be more helpful in
86898686
// reasoning about what went wrong.
86908687
Debug.assert(!!errorNode);
8691-
if (isJsxAttributes(errorNode)) {
8688+
if (isJsxAttributes(errorNode) || isJsxOpeningLikeElement(errorNode)) {
86928689
// JsxAttributes has an object-literal flag and undergo same type-assignablity check as normal object-literal.
86938690
// However, using an object-literal error message will be very confusing to the users so we give different a message.
86948691
reportError(Diagnostics.Property_0_does_not_exist_on_type_1, symbolToString(prop), typeToString(target));
@@ -13303,7 +13300,6 @@ namespace ts {
1330313300
// Handle children attribute
1330413301
const parent = openingLikeElement.parent.kind === SyntaxKind.JsxElement ?
1330513302
openingLikeElement.parent as JsxElement : undefined;
13306-
let containsSynthesizedJsxChildren = false;
1330713303
// We have to check that openingElement of the parent is the one we are visiting as this may not be true for selfClosingElement
1330813304
if (parent && parent.openingElement === openingLikeElement && parent.children.length > 0) {
1330913305
// Error if there is a attribute named "children" and children element.
@@ -13344,8 +13340,7 @@ namespace ts {
1334413340
function createJsxAttributesType(symbol: Symbol, attributesTable: Map<Symbol>) {
1334513341
const result = createAnonymousType(symbol, attributesTable, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined);
1334613342
const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshLiteral;
13347-
const containsSynthesizedJsxChildrenFlag = containsSynthesizedJsxChildren ? TypeFlags.ContainsSynthesizedJsxChildren : 0;
13348-
result.flags |= TypeFlags.JsxAttributes | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | containsSynthesizedJsxChildrenFlag;
13343+
result.flags |= TypeFlags.JsxAttributes | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag;
1334913344
result.objectFlags |= ObjectFlags.ObjectLiteral;
1335013345
return result;
1335113346
}

src/compiler/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2977,8 +2977,6 @@ namespace ts {
29772977
NonPrimitive = 1 << 24, // intrinsic object type
29782978
/* @internal */
29792979
JsxAttributes = 1 << 25, // Jsx attributes type
2980-
/* @internal */
2981-
ContainsSynthesizedJsxChildren = 1 << 26, // Jsx attributes type contains synthesized children property from Jsx element's children
29822980

29832981
/* @internal */
29842982
Nullable = Undefined | Null,

0 commit comments

Comments
 (0)