GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Improve indexed access type relations by ahejlsberg · Pull Request #26698 · microsoft/TypeScript

Conversation

@ahejlsberg

@ahejlsberg Anders Hejlsberg (ahejlsberg) commented Aug 27, 2018

Copy link
Copy Markdown
Member

Fixes #26409.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Anders Hejlsberg (ahejlsberg) added 3 commits August 27, 2018 15:50
@ahejlsberg
Examine all constraints of indexed access types in relations
eeabd52
@ahejlsberg
Add tests
9f83958
@ahejlsberg
Accept new baselines
d369cec
@ahejlsberg
Anders Hejlsberg (ahejlsberg) requested review from Ryan Cavanaugh (RyanCavanaugh) and Wesley Wigham (weswigham) August 27, 2018 23:13
@ahejlsberg

Anders Hejlsberg (ahejlsberg) commented Aug 27, 2018

Copy link
Copy Markdown
Member Author

TypeScript Bot (@typescript-bot) test this

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Aug 27, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

weswigham
Wesley Wigham (weswigham) approved these changes Aug 27, 2018
View reviewed changes

@weswigham Wesley Wigham (weswigham) left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/compiler/checker.ts
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);

@weswigham Wesley Wigham (weswigham) Aug 27, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ahejlsberg Anders Hejlsberg (ahejlsberg) Aug 28, 2018

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/compiler/checker.ts
if (t.flags & TypeFlags.Substitution) {
return getBaseConstraint((<SubstitutionType>t).substitute);
}
if (isGenericMappedType(t)) {

@weswigham Wesley Wigham (weswigham) Aug 27, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ahejlsberg Anders Hejlsberg (ahejlsberg) Aug 28, 2018

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ahejlsberg
Anders Hejlsberg (ahejlsberg) merged commit bd40583 into master Aug 28, 2018
@ahejlsberg
Anders Hejlsberg (ahejlsberg) deleted the indexedAccessConstraints branch August 28, 2018 01:14
@ahejlsberg Anders Hejlsberg (ahejlsberg) mentioned this pull request Aug 28, 2018
Object values are not assignable when wrapped in a Partial #26266
Closed
@sandersn Nathan Shively-Sanders (sandersn) mentioned this pull request Aug 28, 2018
🤖 User test baselines have changed #26712
Closed
@sandersn

Nathan Shively-Sanders (sandersn) commented Aug 28, 2018

Copy link
Copy Markdown
Member

Anders Hejlsberg (@ahejlsberg) This causes some good errors to disappear in the user tests. Mind taking a look? #26712

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) mentioned this pull request Aug 28, 2018
Regression - able to use union containing non-indexing type as index #26714
Closed
@RyanCavanaugh

Ryan Cavanaugh (RyanCavanaugh) commented Aug 28, 2018

Copy link
Copy Markdown
Member

Logged #26714

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ahejlsberg Anders Hejlsberg (ahejlsberg) mentioned this pull request Sep 20, 2018
Regression: something is wrong with type checking in dev.20180919 #27223
Closed
@mattmccutchen Matt McCutchen (mattmccutchen) mentioned this pull request Oct 14, 2018
Change in generic behavior between 3.0.1 and >=3.1.1 #27895
Closed
@jakebailey Jake Bailey (jakebailey) mentioned this pull request Jun 30, 2023
Constraints which are generic mapped types should have a constraint of the same mapping over their generic's constraint #21249
Closed
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
@typescript-bot TypeScript Bot (typescript-bot) assigned Anders Hejlsberg (ahejlsberg) Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@weswigham Wesley Wigham (weswigham) weswigham approved these changes
@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) Awaiting requested review from RyanCavanaugh

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@ahejlsberg Anders Hejlsberg (ahejlsberg)

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@ahejlsberg @typescript-bot @sandersn @RyanCavanaugh @weswigham
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.