You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Recursive Mapped Conditional Type inferring top-level children to any #25860
Search Terms: any recursive mapped conditional inference
Code
interfaceMyNumbers{cool: {mysteriouslySo: number;comfortablySo: number;};scary: {ominouslySo: number;};}typeMapLeaves<OldShape,NewLeaf>=OldShapeextends{}
? {[kinkeyofOldShape]: MapLeaves<OldShape[k],NewLeaf>}
: NewLeaf;// This is inferring as { cool: any, scary: any }, not what I expected!typeMyStrings=MapLeaves<MyNumbers,string>;
Expected behavior:
I'm not sure if I'm misusing recursive mapped conditional types here, but I expected MyStrings to be
Duplicate of #23897. The types are actually computed correctly, but our type display logic doesn't currently descend into recursive mapped types because they could potentially be infinite.
Here, ShouldBeString is indeed of type string. By the way, note that I had to change {} to object in your conditional type. The {} type is actually a supertype of every type but null or undefined, whereas object is a supertype of only objects (and not primitive types).
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Activity
ahejlsberg commentedon Jul 22, 2018
Duplicate of #23897. The types are actually computed correctly, but our type display logic doesn't currently descend into recursive mapped types because they could potentially be infinite.
Here,
ShouldBeStringis indeed of typestring. By the way, note that I had to change{}toobjectin your conditional type. The{}type is actually a supertype of every type butnullorundefined, whereasobjectis a supertype of only objects (and not primitive types).osdiab commentedon Jul 22, 2018
Ah, interesting. Sounds like displaying it with some kind of ellipsis or placeholder type would be more ideal. I'll post to that issue.
typescript-bot commentedon Aug 1, 2018
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.