Skip to content

Port TS#60528: Fix index type deferral crash on generic mapped types with name types#2750

Merged
jakebailey merged 2 commits intomainfrom
copilot/fix-index-type-deferral-crash
Feb 12, 2026
Merged

Port TS#60528: Fix index type deferral crash on generic mapped types with name types#2750
jakebailey merged 2 commits intomainfrom
copilot/fix-index-type-deferral-crash

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 11, 2026

Ports microsoft/TypeScript#60528. Generic mapped types with as clause name types could crash when computing index types due to incorrect deferral logic and missing base constraint handling.

Changes

  • shouldDeferIndexType: Simplify condition from !hasDistributiveNameType(t) || getMappedTypeNameTypeKind(t) == Remapping to getNameTypeFromMappedType(t) != nil — any generic mapped type with an as clause now defers
  • Remove hasDistributiveNameType: No longer referenced after the above simplification
  • computeBaseConstraint: For TypeFlagsIndex targeting a generic mapped type with a name type (non-homomorphic), recursively compute base constraint from the mapped type's index type instead of unconditionally returning stringNumberSymbolType
  • getBaseConstraintOfType: Route TypeFlagsIndex through getResolvedBaseConstraint instead of short-circuiting
  • TypeFlagsSimplifiable: Add TypeFlagsIndex to the flag set
  • Unskip mappedTypeAsClauseRecursiveNoCrash1.ts test
// Previously crashed or produced incorrect results:
type Mapped<K extends string> = { [P in K as `_${P}`]: true };
function f<K extends string>(key: keyof Mapped<K>) {
    let s: `_${string}` = key; // now correctly resolves constraint
}

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…n generic mapped types with name types

Changes:
- Simplify shouldDeferIndexType to check for name type existence instead of distributive name type
- Remove hasDistributiveNameType function (no longer needed)
- Add TypeFlagsIndex to TypeFlagsSimplifiable
- Handle generic mapped types with name types in computeBaseConstraint
- Route TypeFlagsIndex through getResolvedBaseConstraint in getBaseConstraintOfType
- Unskip mappedTypeAsClauseRecursiveNoCrash1.ts test
- Accept baseline changes

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix crash related to index type deferral on generic mapped types Port TS#60528: Fix index type deferral crash on generic mapped types with name types Feb 11, 2026
Copilot AI requested a review from jakebailey February 11, 2026 00:47
@jakebailey jakebailey marked this pull request as ready for review February 11, 2026 00:51
Copilot AI review requested due to automatic review settings February 11, 2026 00:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Ports TypeScript PR #60528 to prevent crashes and improve constraint computation for index types on generic mapped types that use as clause name types.

Changes:

  • Adjust index-type deferral for generic mapped types with as clauses and remove obsolete distributive-name-type logic.
  • Improve base-constraint resolution for TypeFlagsIndex when targeting certain generic mapped types with name types.
  • Re-enable the mappedTypeAsClauseRecursiveNoCrash1.ts regression test and update affected baselines.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/checker/checker.go Updates deferral/base-constraint logic for index types involving generic mapped types; removes hasDistributiveNameType.
internal/checker/types.go Adds TypeFlagsIndex to TypeFlagsSimplifiable so index types participate in simplification/constraint flows.
internal/testrunner/compiler_runner.go Unskips mappedTypeAsClauseRecursiveNoCrash1.ts.
testdata/baselines/reference/submodule/conformance/mappedTypeConstraints2.* Updates baselines for mapped type constraint and error output changes.
testdata/baselines/reference/submodule/conformance/mappedTypeAsClauseRecursiveNoCrash1.* Adds new baseline outputs for the re-enabled regression test.
testdata/baselines/reference/submodule/compiler/keyRemappingKeyofResult2.errors.txt* Removes baseline error output (now empty/no longer applicable).
Comments suppressed due to low confidence (2)

internal/checker/checker.go:1

  • This comment now states there is 'a key remapping', but the condition guarding it is isMappedTypeWithKeyofConstraintDeclaration(t) plus a generic index constraint; that doesn’t necessarily imply an as-clause remapping is present. Consider rewording the comment to describe the actual condition (generic index + homomorphic mapping via keyof constraint) or tighten the code to only enter this path when a name type exists (e.g., getNameTypeFromMappedType(t) != nil) if that’s what the comment intends.
    internal/checker/checker.go:1
  • This block calls t.AsIndexType() twice and repeats .target access. Consider storing index := t.AsIndexType() and mappedType := index.target once to make the control flow clearer and avoid duplicated accessor calls.

@jakebailey jakebailey enabled auto-merge February 11, 2026 01:33
@jakebailey jakebailey added this pull request to the merge queue Feb 12, 2026
Merged via the queue into main with commit 28bb535 Feb 12, 2026
26 checks passed
@jakebailey jakebailey deleted the copilot/fix-index-type-deferral-crash branch February 12, 2026 17:43
Copilot AI added a commit that referenced this pull request Feb 25, 2026
…with name types (#2750)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants