[4.3, 4.4] Inline filtering mapped type conditional with infer
fails
#46020
Labels
Bug
A bug in TypeScript
Needs Investigation
This issue needs a team member to investigate its status.
Rescheduled
This issue was previously scheduled to an earlier milestone
Milestone
Bug Report
As of TypeScript 4.3, when inlining a mapped type on the left-hand side of
extends
in a conditional type, TypeScript incorrectly evaluates the condition when the right-hand side contains another mapped type withinfer
and renders the false condition. When declaring the mapped type explicitly rather than inline, the ternary is correctly evaluated.This is pretty hard to cover in words, so please check playground link for reproduction.
The language version can be changed to 4.2 to see it working correctly.
🔎 Search Terms
typescript infer inline mapped type never generic inference
🕗 Version & Regression Information
⏯ Playground Link
Change TS language to 4.2 to see the code functioning correctly, and 4.3 or 4.4 to see failure.
Playground link with relevant code
💻 Code
🙁 Actual behavior
In the above code sample, the type
FailingKnownFlags
isnever
(the false branch of the ternary ofFailingKnownKeys<T>
), whileKnownFlags
correctly is{knownFlag1: boolean, knownFlag2: boolean}
🙂 Expected behavior
They are the same declaration, just one being inline and the other with an explicitly extracted type.
The text was updated successfully, but these errors were encountered: