Improve indexed access type relations#26698
Conversation
|
@typescript-bot test this |
|
Heya @ahejlsberg, I've started to run the extended test suite on this PR at d369cec. You can monitor the build here. It should now contribute to this PR's status checks. |
| return constraint && constraint !== errorType ? constraint : undefined; | ||
| const objectType = getConstraintOfType(type.objectType) || type.objectType; | ||
| if (objectType !== type.objectType) { | ||
| const constraint = getIndexedAccessType(objectType, type.indexType, /*accessNode*/ undefined, errorType); |
There was a problem hiding this comment.
Wouldn't this still result in a type we may need to get the constraint of if the constraint of tyoe.objectType is a generic mapped type (since an index on a mapped type is trivially bounded by the mapped type's template)? Or is getConstraintOfType not the variant that can do that?
There was a problem hiding this comment.
If the constraint of type.objectType is a mapped type, we do indeed fetch that here and form a new indexed access. If type.objectType itself is a mapped type, the getConstraintOfType function does nothing, and we'll fall into the base constraint code below.
| if (t.flags & TypeFlags.Substitution) { | ||
| return getBaseConstraint((<SubstitutionType>t).substitute); | ||
| } | ||
| if (isGenericMappedType(t)) { |
There was a problem hiding this comment.
This makes the constraint of a generic mapped type itself, right? I guess that makes sense since indexed accesses work that way already.
There was a problem hiding this comment.
Correct. I'm not sure why this code was here, but it definitely isn't right. Removing it had no effect on baselines (including RWC baselines), but it fixes the second issue I found while exploring #26409.
|
@ahejlsberg This causes some good errors to disappear in the user tests. Mind taking a look? #26712 |
|
Logged #26714 |
Fixes #26409.