@@ -11102,7 +11102,7 @@ namespace ts {
11102
11102
function getJsxAttributesSymbolArrayFromAttributesProperty(openingLikeElement: JsxOpeningLikeElement): Symbol[] | undefined {
11103
11103
const attributes = openingLikeElement.attributes;
11104
11104
let attributesTable = createMap<Symbol>();
11105
- const spreads : Type[] = [];
11105
+ let spread : Type = emptyObjectType
11106
11106
let attributesArray: Symbol[] = [];
11107
11107
for (const attributeDecl of attributes.properties) {
11108
11108
const member = attributeDecl.symbol;
@@ -11130,27 +11130,28 @@ namespace ts {
11130
11130
else {
11131
11131
Debug.assert(attributeDecl.kind === SyntaxKind.JsxSpreadAttribute);
11132
11132
if (attributesArray.length > 0) {
11133
- spreads.push( createJsxAttributesType(attributes, attributesTable));
11133
+ spread = getSpreadType(spread, createJsxAttributesType(attributes.symbol , attributesTable), attributes.symbol );
11134
11134
attributesArray = [];
11135
11135
attributesTable = createMap<Symbol>();
11136
11136
}
11137
11137
const exprType = checkExpression(attributeDecl.expression);
11138
+ if (!(getWidenedType(exprType).flags & (TypeFlags.Object | TypeFlags.Any))) {
11139
+ error(attributeDecl, Diagnostics.Spread_types_may_only_be_created_from_object_types);
11140
+ return undefined;
11141
+ }
11138
11142
if (isTypeAny(getWidenedType(exprType))) {
11139
11143
return undefined;
11140
11144
}
11141
- spreads.push( exprType);
11145
+ spread = getSpreadType(spread, exprType, attributes.symbol );
11142
11146
}
11143
11147
}
11144
11148
11145
- if (spreads.length > 0 ) {
11149
+ if (spread !== emptyObjectType ) {
11146
11150
if (attributesArray.length > 0) {
11147
- spreads.push( createJsxAttributesType(attributes, attributesTable));
11151
+ spread = getSpreadType(spread, createJsxAttributesType(attributes.symbol , attributesTable), attributes.symbol );
11148
11152
attributesArray = [];
11149
11153
attributesTable = createMap<Symbol>();
11150
11154
}
11151
- const propagatedFlags = getPropagatingFlagsOfTypes(spreads, /*excludeKinds*/ TypeFlags.Nullable);
11152
- const spread = getSpreadType(spreads, attributes.symbol);
11153
- spread.flags |= propagatedFlags;
11154
11155
attributesArray = getPropertiesOfType(spread);
11155
11156
}
11156
11157
@@ -11159,13 +11160,14 @@ namespace ts {
11159
11160
11160
11161
/**
11161
11162
* Create anonymous type from given attributes symbol table.
11162
- * @param jsxAttributes a JsxAttributes node containing attributes in attributesTable
11163
+ * @param jsxAttributesSymb a JsxAttributes node containing attributes in attributesTable
11163
11164
* @param attributesTable a symbol table of attributes property
11164
11165
*/
11165
- function createJsxAttributesType(jsxAttributes: JsxAttributes , attributesTable: Map<Symbol>) {
11166
- const result = createAnonymousType(jsxAttributes.symbol , attributesTable, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined);
11166
+ function createJsxAttributesType(jsxAttributesSymb: Symbol , attributesTable: Map<Symbol>) {
11167
+ const result = createAnonymousType(jsxAttributesSymb , attributesTable, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined);
11167
11168
const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshLiteral;
11168
- result.flags |= TypeFlags.JsxAttributes | TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag;
11169
+ result.flags |= TypeFlags.JsxAttributes | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag;
11170
+ result.objectFlags |= ObjectFlags.ObjectLiteral;
11169
11171
return result;
11170
11172
}
11171
11173
@@ -11182,7 +11184,7 @@ namespace ts {
11182
11184
forEach(symbolArray, (attr) => {
11183
11185
symbolTable[attr.name] = attr;
11184
11186
});
11185
- argAttributesType = createJsxAttributesType(node, symbolTable);
11187
+ argAttributesType = createJsxAttributesType(node.symbol , symbolTable);
11186
11188
}
11187
11189
return argAttributesType;
11188
11190
}
@@ -11219,7 +11221,7 @@ namespace ts {
11219
11221
}
11220
11222
});
11221
11223
11222
- sourceAttributesType = createJsxAttributesType(openingLikeElement.attributes, symbolTable);
11224
+ sourceAttributesType = createJsxAttributesType(openingLikeElement.attributes.symbol , symbolTable);
11223
11225
}
11224
11226
11225
11227
// If the targetAttributesType is an emptyObjectType, indicating that there is no property named 'props' on this instance type.
@@ -12325,7 +12327,7 @@ namespace ts {
12325
12327
* @param relation a relationship to check parameter and argument type
12326
12328
* @param excludeArgument
12327
12329
*/
12328
- function checkApplicableSignatureForJsxOpeningLikeElement(node: JsxOpeningLikeElement, signature: Signature, relation: Map<RelationComparisonResult>, excludeArgument: boolean[] ) {
12330
+ function checkApplicableSignatureForJsxOpeningLikeElement(node: JsxOpeningLikeElement, signature: Signature, relation: Map<RelationComparisonResult>) {
12329
12331
const headMessage = Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1;
12330
12332
// Stateless function components can have maximum of three arguments: "props", "context", and "updater".
12331
12333
// However "context" and "updater" are implicit and can't be specify by users. Only the first parameter, props,
@@ -12944,7 +12946,7 @@ namespace ts {
12944
12946
}
12945
12947
candidate = getSignatureInstantiation(candidate, typeArgumentTypes);
12946
12948
}
12947
- if (isJsxOpeningOrSelfClosingElement && !checkApplicableSignatureForJsxOpeningLikeElement(<JsxOpeningLikeElement>node, candidate, relation, excludeArgument )) {
12949
+ if (isJsxOpeningOrSelfClosingElement && !checkApplicableSignatureForJsxOpeningLikeElement(<JsxOpeningLikeElement>node, candidate, relation)) {
12948
12950
break;
12949
12951
}
12950
12952
else if (!isJsxOpeningOrSelfClosingElement && !checkApplicableSignature(node, args, candidate, relation, excludeArgument, /*reportErrors*/ false)) {
0 commit comments