Skip to content

Fix crash in visitEachChildOfIndexSignatureDeclaration when type is missing#63267

Closed
mango766 wants to merge 1 commit intomicrosoft:mainfrom
mango766:fix/index-signature-missing-type-crash
Closed

Fix crash in visitEachChildOfIndexSignatureDeclaration when type is missing#63267
mango766 wants to merge 1 commit intomicrosoft:mainfrom
mango766:fix/index-signature-missing-type-crash

Conversation

@mango766
Copy link
Copy Markdown

Fixes #63230

Problem

When a malformed index signature like {[key: string], any} (comma instead of colon) is parsed, the IndexSignatureDeclaration node is created without a type property. This is expected — the parser already handles this case, and there's even a TODO comment in createIndexSignature acknowledging it:

node.type = type!; // TODO(rbuckton): We mark this as required in IndexSignatureDeclaration, but it looks like the parser allows it to be elided.

However, visitEachChildOfIndexSignatureDeclaration uses Debug.checkDefined(nodeVisitor(node.type, ...)) which throws a Debug Failure instead of allowing the compiler to report a proper diagnostic error.

Fix

Replace Debug.checkDefined(...) with the non-null assertion operator (!), matching the existing pattern used by createIndexSignature for the same situation. When node.type is undefined, nodeVisitor returns undefined, and the ! allows it to propagate through updateIndexSignature — which already handles the case gracefully (it compares node.type !== type, sees they're both undefined/the same, and returns the original node unchanged).

Minimal repro (from @RyanCavanaugh's comment)

export const f = (x: {[key: string], any}) => 0;

Before: Error: Debug Failure.
After: proper diagnostic errors are reported.

…issing

When a malformed index signature like `{[key: string], any}` is parsed,
the resulting IndexSignatureDeclaration node has no `type` property.
The `Debug.checkDefined()` call in the visitor then throws a "Debug
Failure" error instead of allowing the compiler to report a proper
diagnostic.

Replace `Debug.checkDefined(...)` with the non-null assertion operator
(`!`), which is consistent with how `createIndexSignature` in
nodeFactory.ts already handles a potentially-undefined type (line 2234).

Fixes microsoft#63230
@typescript-bot
Copy link
Copy Markdown
Collaborator

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

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Compiler crash: Debug Failure in visitEachChildOfIndexSignatureDeclaration

2 participants