Skip to content

Fixed an issue with optionality not being stripped from generic mapped types on indexed access #59921

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

fixes #59902

@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Sep 10, 2024
@@ -19103,9 +19103,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const mapper = createTypeMapper([getTypeParameterFromMappedType(objectType)], [index]);
const templateMapper = combineTypeMappers(objectType.mapper, mapper);
const instantiatedTemplateType = instantiateType(getTemplateTypeFromMappedType(objectType.target as MappedType || objectType), templateMapper);
const isOptional = getMappedTypeOptionality(objectType) > 0 || (isGenericType(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.

In the given repro the immediate modifiers type has -? for which getMappedTypeOptionality returns -1. So the first condition was not satisfied and the compiler proceeded to compute getCombinedMappedTypeOptionality. This time it was called with the modifiers type and not the original object type. Since that was a mapped type too it got its modifiers type etc.

Essentially this was skipping the outermost mapped type modifiers in this scenario - the ones that were supposed strip the optionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Status: Not started
Development

Successfully merging this pull request may close these issues.

Removing optional modifier in homomorphic mapped types does not work in generic contexts since 5.5.x
3 participants