Mapped type of a conditional type unexpectedly fails inference #59323
Labels
Help Wanted
You can do this
Possible Improvement
The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
🔎 Search Terms
conditional type infer unknown
conditional type mapped type inference
🕗 Version & Regression Information
This is the behavior in every version I tried (3.3.3 to 5.5.3), and I reviewed the FAQ for entries about conditional types, mapped types, and structural inference.
⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.5.3#code/C4TwDgpgBAsghmSATAPAFQHxQLxQN5QDaAClAJYB2UA1hCAPYBmUaAugFwsmtQC+AUP1CQoAYXoBbMPQoQKwAII5YCZCgKMyEADZJOFAK4SARhABOfDIOHRxUmXOAAhZRq279R0xYFDw0AEkKRnMARnQsXHhECFQ0KAgAD2A5JABnKFkAN3MoAH5Mg21tKE5MQSQIAGNtODNoRgMKKuAyGXJgsIiACirOIJCzcMwASjL+SkHQ7rxeKDgMu2lZeQURgDpNHSRlUKgoAHoDqEBQcgnOoZm5hbFJZccnDa3dXf2jqEAZcigAUTMzejMnAA8sYAFbVYDkDJMKA2KAAcia1Ao9AA7hR4YI-CIBuYAEwRZTxJIpCjpTIQHIWAqGYqlFQxOJWfiVGp1BpNFptKiTfE9PpQXFmAmjca84VXeaLO4OVZPdw7XB7Q7HM7ivGSm5LWXOeXbV4q078IA
💻 Code
🙁 Actual behavior
infer1(ComponentA)
passed inference butinfer1(ComponentB)
failed withunknown
.However, if it's the other way around —
Conditional ? Mapped<T>
instead ofMapped<Conditional ? T>
, bothinfer2(ComponentA)
andinfer2(ComponentB)
passed inference.🙂 Expected behavior
I expect
infer1(ComponentA)
andinfer1(ComponentB)
to both work, becauseComponentA
andComponentB
are essentially the same type — I'm unable to otherwise differentiate them by any means.Additional information about the issue
I discovered this while debugging vuejs/core#11353, and the interference failure there was eventually reduced to this report.
The text was updated successfully, but these errors were encountered: