Transformers in a map generated via a Mapped Type with Key Remapping are erroneously inferred to return any
#57097
Labels
Fixed
A PR has been merged for this issue
π Search Terms
"mapped types", "key remapping", "indexed access type"
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?target=99&ts=5.4.0-dev.20240119#code/KYDwDg9gTgLgBDAnmYcByEAmwCSA7GYKAMwEMBjYAHgBkBLQqUgGwBVlVRC9MBnOXjCh08AczgBeAUJGiAfJLgBvAFBx1CDgC449Ri3YoA3CoC+JlaEixNKOAGUidFnQBewTPZliAssBikigBKwOTQmFSCwmIANNLR4gA+cACuPMDEIh5yFlbQ8Eh2ACIQALYAoiBCFISYGNhFpAGKqhpweFjAhsA6UbImbaX+pDqOwi7unt6ifgEm5iqW4Pm2qPVdECWlY87MbkRU63BcwDz86-iMZJQKUgAUahod2DrrMSoAlJIKOxMeXglZqRcssbIU1p0gb89u4oD5SGBDp0AKp4OgQPDHKqnPjoTqXIjXYC3ZSPdQAbSOIjx2FR6MxpHOnXJAHJwSyALoc16dVibMrQ-ZQJHYHJmCxhPCCOAAC0ZiiorCx3FxEAARgArUIwOQPNoQHSsd5tADWvWmcGSeBSpTVREtAkQtogzHeHx0JrgdH4JuAiAgxDgSokCgA8prtQA6OW8UMAdzwdwgcRNHwlGOlQkQgvcyN4snhYDAsgVSpOZxpuAIhIoxL1GlKCOLYh52ChTj+cIRirkxqenUNbu+pLadEDdxjd0bRdkcWewEj4I+X1abQ0kulgSk0+bonJ88XHA5FjX64z8DVilId3nacWp-UUH8KSgDJvnTvbVM940MBlUAgON2mAIDunKKAAKgO4WVRXgUiLfIPHaTpVhZO9zCAA
π» Code
π Actual behavior
Type of the variable
a
is correctly inferred to beNodeMetaSerializerMap<T>[keyof NodeMetaSerializerMap<T>]
. To be rigorous this should beNodeToDomSerializer<T>
.Type of variable
b
, however, is inferred to beany
. Compiler doesn't warn me about this, and as you can understand, this could lead to all sorts of potentialany
-leakages. Compiler optionstrict
doesn't change this as well.π Expected behavior
I expect type of the variable
b
to be correctly inferred asSerializedStringMeta
, or at least some kind of error to be shown in the call site ofa(node)
.Additional information about the issue
I've also reviewed this pull request. I've tried the following work-around:
This results in a following error being shown at the call site for
a(node)
:This also seems like a weird behaviour, because I've tested different things and verified that
TypeToNodeMapping<NodeInterface>[NodeInterface['type']]
is correctly resolved asNodeInterface
. Seems to me like the compiler is for some reason refusing to unpack the types further, despite the fact it seems safe to use the upper boundaryNodeInterface
when resolving types forT
.The text was updated successfully, but these errors were encountered: