-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Improve isValidSpreadType check #47010
Conversation
return !!(type.flags & (TypeFlags.Any | TypeFlags.NonPrimitive | TypeFlags.Object | TypeFlags.InstantiableNonPrimitive) || | ||
getFalsyFlags(type) & TypeFlags.DefinitelyFalsy && isValidSpreadType(removeDefinitelyFalsyTypes(type)) || | ||
type.flags & TypeFlags.UnionOrIntersection && every((type as UnionOrIntersectionType).types, isValidSpreadType)); | ||
const t = removeDefinitelyFalsyTypes(mapType(type, getBaseConstraintOrType)); |
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.
love that we have functions named getBaseConstraintOrType
and getBaseConstraintOfType
@@ -20857,7 +20857,7 @@ namespace ts { | |||
// flags for the string, number, boolean, "", 0, false, void, undefined, or null types respectively. Returns | |||
// no flags for all other types (including non-falsy literal types). | |||
function getFalsyFlags(type: Type): TypeFlags { | |||
return type.flags & TypeFlags.Union ? getFalsyFlagsOfTypes((type as UnionType).types) : | |||
return type.flags & TypeFlags.UnionOrIntersection ? getFalsyFlagsOfTypes((type as UnionType).types) : |
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'm a little surprised that adding intersections to getFalsyFlags didn't change any existing baselines.
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.
Well, there are precious few intersections that would be affected, pretty much only those like T & undefined
that will now appear to be falsy.
Regression: #47028 (comment) |
* Fix getFalsyFlags for intersection types * Fix and simplify isValidSpreadType * Slight tweak * Add tests
Fixes #46976.