-
Notifications
You must be signed in to change notification settings - Fork 12.8k
fix #49235 Objects that pass the spread syntax can no longer be assigned to assignable types. #49337
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
Conversation
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 think this is correct, although I'd like to get a second opinion from @gabritto. I have a couple of suggestions too.
src/compiler/checker.ts
Outdated
return type.flags & TypeFlags.Intersection | ||
? every((type as IntersectionType).types, isObjectTypeWithInferableIndex) | ||
: !!( | ||
type.symbol | ||
&& (type.symbol.flags & (SymbolFlags.ObjectLiteral | SymbolFlags.TypeLiteral | SymbolFlags.Enum | SymbolFlags.ValueModule)) !== 0 | ||
&& !(type.symbol.flags & SymbolFlags.Class) | ||
&& !typeHasCallOrConstructSignatures(type) | ||
) || !!( | ||
objectFlags |
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.
getObjectFlags always returns a value, so you don't need to check for undefined (or 0)
src/compiler/checker.ts
Outdated
return type.flags & TypeFlags.Intersection | ||
? every((type as IntersectionType).types, isObjectTypeWithInferableIndex) | ||
: !!( | ||
type.symbol | ||
&& (type.symbol.flags & (SymbolFlags.ObjectLiteral | SymbolFlags.TypeLiteral | SymbolFlags.Enum | SymbolFlags.ValueModule)) !== 0 | ||
&& !(type.symbol.flags & SymbolFlags.Class) | ||
&& !typeHasCallOrConstructSignatures(type) | ||
) || !!( | ||
objectFlags | ||
&& objectFlags & ObjectFlags.ObjectRestType | ||
) || !!(getObjectFlags(type) & ObjectFlags.ReverseMapped && isObjectTypeWithInferableIndex((type as ReverseMappedType).source)); |
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.
Can you replace getObjectFlags(type)
with objectFlags
here too? getObjectFlags is likely to be inlined, so you could also call it from each place.
@sandersn I have made updates accordingly, thank you for the review :) |
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'll leave for a few days to see what @gabritto thinks.
Fixes #49235