Skip to content

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

Closed
Mateusz Burzyński (Andarist) wants to merge 1 commit into
microsoft:mainfrom
Andarist:fix/generic-mapped-type-optionality-stripped
Closed

Fixed an issue with optionality not being stripped from generic mapped types on indexed access#59921
Mateusz Burzyński (Andarist) wants to merge 1 commit into
microsoft:mainfrom
Andarist:fix/generic-mapped-type-optionality-stripped

Conversation

@Andarist

Copy link
Copy Markdown
Contributor

fixes #59902

Comment thread src/compiler/checker.ts
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
Copy Markdown
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.

@typescript-bot

Copy link
Copy Markdown
Contributor

With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies).

Next steps for PRs:

  • For crash bugfixes or language service improvements, PRs are currently accepted at the typescript-go repo
  • Changes to type system behavior should wait until after 7.0, at which point mainline TypeScript development will resume in this repository with the Go codebase
  • Library file updates (lib.d.ts etc) continue to live in this repo or the DOM Generator repo as appropriate

@github-project-automation github-project-automation Bot moved this from Not started to Done in PR Backlog Mar 24, 2026
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: Done

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

4 participants