Skip to content

Conversation

@ahejlsberg
Copy link
Member

Fixes #46976.

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Dec 3, 2021
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));
Copy link
Member

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

// 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) :
Copy link
Member

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.

Copy link
Member Author

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.

@ahejlsberg ahejlsberg merged commit b2af605 into main Dec 4, 2021
@ahejlsberg ahejlsberg deleted the fix46976 branch December 4, 2021 00:11
@RyanCavanaugh
Copy link
Member

Regression: #47028 (comment)

mprobst pushed a commit to mprobst/TypeScript that referenced this pull request Jan 10, 2022
* Fix getFalsyFlags for intersection types

* Fix and simplify isValidSpreadType

* Slight tweak

* Add tests
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: Team For Milestone Bug PRs that fix a bug with a specific milestone

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(T | undefined) & T has different behavior when T is known versus when T is a type variable

5 participants