Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jan 29, 2024

Conversation

Andarist
Copy link
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
Collaborator

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

@@ -14230,7 +14230,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

function getConstraintFromIndexedAccess(type: IndexedAccessType) {
if (isMappedTypeGenericIndexedAccess(type) || isGenericMappedType(type.objectType)) {
Copy link
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

@@ -57,5 +83,5 @@ type ObjectWithUnderscoredKeys<K extends string> = {
};

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
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
19 checks passed
@Andarist Andarist deleted the revert/53066 branch January 29, 2024 21:00
@weswigham
Copy link
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
Member

Yeah, it'll be in the RC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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