Skip to content

Revert "Always substitute indexed generic mapped type when getting constraint from indexed access"#57202

Merged
weswigham merged 2 commits into
microsoft:mainfrom
Andarist:revert/53066
Jan 29, 2024
Merged

Revert "Always substitute indexed generic mapped type when getting constraint from indexed access"#57202
weswigham merged 2 commits into
microsoft:mainfrom
Andarist:revert/53066

Conversation

@Andarist

Copy link
Copy Markdown
Contributor

reverts my own #53066 , fixes #53066 (comment)

cc @ahejlsberg @weswigham

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jan 28, 2024
@typescript-bot

Copy link
Copy Markdown
Contributor

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

Comment thread src/compiler/checker.ts
}

function getConstraintFromIndexedAccess(type: IndexedAccessType) {
if (isMappedTypeGenericIndexedAccess(type) || isGenericMappedType(type.objectType)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while my comment here can be partially true - so far I couldn't find the situation in which this extra check would benefit anything (after adjustments) since getSimplifiedIndexedAccessType already performs this substitution when it's safe to do so


function genericTest<K extends string>(objectWithUnderscoredKeys: ObjectWithUnderscoredKeys<K>, key: K) {
const shouldBeTrue: true = objectWithUnderscoredKeys[`_${key}`];
const shouldBeTrue: true = objectWithUnderscoredKeys[`_${key}`]; // assignability fails here, but ideally should not

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those kinds of cases could always be OK if we could determine that the template type doesn't depend on the original K. I don't think the compiler is equipped to check this sort of thing right now though.

@weswigham weswigham merged commit 01527ce into microsoft:main Jan 29, 2024
@Andarist Andarist deleted the revert/53066 branch January 29, 2024 21:00
@weswigham

Copy link
Copy Markdown
Member

@DanielRosenwasser I don't think this revert needs to be cherry-picked or anything, right? Since we'll sync the release branch with main again for the rc.

@DanielRosenwasser

Copy link
Copy Markdown
Member

Yeah, it'll be in the RC

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants