Port TypeScript PR #60528: Fix crash on index type deferral for generic mapped types with name types #2519
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.
Ports microsoft/TypeScript#60528, which fixes crashes when computing index types for generic mapped types with name types. Previously, the type checker would crash or incorrectly defer index type resolution in cases like:
Changes
TypeFlagsIndexto simplifiable types - Enables simplification of index types for mapped typeshasDistributiveNameTypefunction - The distributive check is no longer needed; simplified to just checking if a name type existsshouldDeferIndexType- Changed from complex distributive checks to simple presence check:getNameTypeFromMappedType(t) != nilgetSimplifiedIndexType- New simplification path for index types on generic mapped types with name types but without keyof constraint declarationscheckIndexedAccessIndexType- Removed conditional logic, now always usesgetIndexTypeExinternal/checker/checker_test.go:TestKeyRemappingKeyofResult2- Validates fix forkeyof FilteringMappedTypecan't compute its constraint TypeScript#56239TestMappedTypeAsClauseRecursiveNoCrash- Validates fix for Regression: Mapped type with recursive key remapping crashes tsc with "RangeError: Maximum call stack size exceeded" in TS@5.4+ TypeScript#60476Impact
Error messages are now more readable:
Type 'Mapped6<K>[string] | Mapped6<K>[number] | Mapped6<K>[symbol]' is not assignable to...Type 'Mapped6<K>[\_${K}`]' is not assignable to...`Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.