NonNullable
is accidentally simplified away from generic index accesses
#50539
Labels
Fix Available
A PR has been opened for this issue
Needs Investigation
This issue needs a team member to investigate its status.
Milestone
Bug Report
π Search Terms
defer, index access, index signature, nonnullable
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
NonNullable
disappears when computinggetConstraintFromIndexedAccess
. Essentially this type:gets simplified/distributed to
As we might notice here -
NonNullable
is gone from here because of the simplification rules:The third case applies here so we end up with something like this
In here, those
{}[string | number | symbol]
are just reduced tounknown
andT & unknown
gets reduced toT
. So that's howNonNullable
"disappears" here.Note that even though
T[number | symbol]
is not valid for thisT
this indexed access is allowed based on this logic:https://github.dev/microsoft/TypeScript/blob/488d0eebd0556fcc6e5f4cfc69c2ef7e5c2708ed/src/compiler/checker.ts#L16036-L16040
π Expected behavior
NonNullable
should be correctly retained/deferred in this case to preserve the correct constraint of the generic type.The text was updated successfully, but these errors were encountered: