@@ -3098,7 +3098,7 @@ namespace ts {
3098
3098
let type: Type;
3099
3099
if (pattern.kind === SyntaxKind.ObjectBindingPattern) {
3100
3100
if (declaration.dotDotDotToken) {
3101
- if (isInvalidSpreadType (parentType)) {
3101
+ if (!isValidSpreadType (parentType)) {
3102
3102
error(declaration, Diagnostics.Rest_types_may_only_be_created_from_object_types);
3103
3103
return unknownType;
3104
3104
}
@@ -11449,7 +11449,7 @@ namespace ts {
11449
11449
typeFlags = 0;
11450
11450
}
11451
11451
const type = checkExpression((memberDecl as SpreadAssignment).expression);
11452
- if (!(type.flags & TypeFlags.Any) && isInvalidSpreadType (type)) {
11452
+ if (!isValidSpreadType (type)) {
11453
11453
error(memberDecl, Diagnostics.Spread_types_may_only_be_created_from_object_types);
11454
11454
return unknownType;
11455
11455
}
@@ -11527,14 +11527,21 @@ namespace ts {
11527
11527
}
11528
11528
}
11529
11529
11530
- function isInvalidSpreadType(type: Type): boolean {
11530
+ function isValidSpreadType(type: Type): boolean {
11531
+ if (type.flags & TypeFlags.Any) {
11532
+ return true;
11533
+ }
11531
11534
if (type.flags & TypeFlags.Object) {
11532
- return isGenericMappedType(type);
11535
+ return ! isGenericMappedType(type);
11533
11536
}
11534
11537
else if (type.flags & TypeFlags.UnionOrIntersection) {
11535
- return forEach((<UnionOrIntersectionType>type).types, isInvalidSpreadType);
11538
+ for (const t of (<UnionOrIntersectionType>type).types) {
11539
+ if (!isValidSpreadType(t)) {
11540
+ return false;
11541
+ }
11542
+ }
11536
11543
}
11537
- return true ;
11544
+ return false ;
11538
11545
}
11539
11546
11540
11547
function checkJsxSelfClosingElement(node: JsxSelfClosingElement) {
0 commit comments