GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||
GeezerVison is showing github.com — Improve indexed access type relations by ahejlsberg · Pull Request #26698 · microsoft/TypeScript Conversation
Member
Fixes #26409.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Anders Hejlsberg (ahejlsberg)
requested review from
Ryan Cavanaugh (RyanCavanaugh) and
Wesley Wigham (weswigham)
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
|
There was an error while loading. Please reload this page.
|
Heya Anders Hejlsberg (@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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks good - I actually like this more than the existing index type constraint code by a bit - it much more clearly defines the hierarchy of constraints we check. Just some clarifying questions.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| 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.
The reason will be displayed to describe this comment to others. Learn more.
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?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (t.flags & TypeFlags.Substitution) { | ||
| return getBaseConstraint((<SubstitutionType>t).substitute); | ||
| } | ||
| if (isGenericMappedType(t)) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This makes the constraint of a generic mapped type itself, right? I guess that makes sense since indexed accesses work that way already.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Anders Hejlsberg (@ahejlsberg) This causes some good errors to disappear in the user tests. Mind taking a look? #26712 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Logged #26714 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.