To find a thorough explanation to this question, check out microsoft/TypeScript#40049, although it may not fully clarify the underlying reason in my opinion.
Especially take note of this comment:
@jack-williams commented on Aug 14, 2020:
It's not very well-documented outside of the source code, but in the checker, you'll discover at the relevant location:
// Return union of trueType and falseType for 'any' since it matches anything
if (checkType.flags & TypeFlags.Any) {
Thus, any
is considered as a wildcard that can match both branches.
You can currently locate the code on line 15239here (GitHub doesn't allow linking to specific lines in large files like this one), and it was added in this commit within microsoft/TypeScript#21316, the pull request that introduced conditional types. Therefore, this behavior has been consistent since conditional types were implemented.
This essentially explains "why" this occurs. The official reasoning being, "since it matches anything".