Skip to content

Fix nil panic when stripInternal elides type alias RHS - #64770

Merged
Jake Bailey (jakebailey) merged 1 commit into
microsoft:mainfrom
andre-fajar-n:fix/stripInternal-type-alias-nil-panic
Oct 13, 2026
Merged

Jake Bailey (jakebailey) merged 1 commit into
microsoft:mainfrom
andre-fajar-n:fix/stripInternal-type-alias-nil-panic

Conversation

@andre-fajar-n

Copy link
Copy Markdown
Contributor

Fixes #64667

Analysis

With --declaration --stripInternal, @internal on a type-alias RHS can be stripped by visitDeclarationSubtree, leaving a nil
Type on the alias:

interface Foo {}
export type T =
    /** @internal */
    Foo;

Declaration emit then called ast.GetTypeNodePrecedence with nil from emitTypeAliasDeclaration → emitTypeNode, causing:
panic: runtime error: invalid memory address or nil pointer dereference
Index signatures already fall back to any when the visited type is nil; type aliases did not.

Fix

In transformTypeAliasDeclaration, if Visit(input.Type) returns nil, substitute any (same pattern as
transformIndexSignatureDeclaration). Added declarationEmitStripInternalTypeAliasRHS.ts and baselines.
Alternate considered: nil-guard only in emitTypeNode / GetTypeNodePrecedence. That would avoid the crash but could emit an
incomplete alias; transforming to any matches existing stripInternal declaration behavior.

AI Assistance

This PR was authored with AI assistance (Cursor); I have reviewed and understand the changes.

Copilot AI balanced review requested due to automatic review settings October 13, 2026 13:51
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Oct 13, 2026
@typescript-automation typescript-automation Bot added For Backlog Bug PRs that fix a backlog bug labels Oct 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused fallback matches existing index-signature behavior and the regression baseline verifies export type T = any.

0 open findings

What changed in this PR

Fixes declaration emit panics when stripInternal removes a type alias RHS.

Changes:

  • Falls back to any when the transformed RHS is nil.
  • Adds a focused compiler regression test and baselines.
File Description
tsc/​internal/​transformers/​declarations/​transform.go Adds the any fallback.
tsc/​testdata/​tests/​cases/​compiler/​declarationEmitStripInternalTypeAliasRHS.ts Reproduces the panic.
tsc/​testdata/​baselines/​reference/​compiler/​declarationEmitStripInternalTypeAliasRHS.js Verifies declaration output.
tsc/​testdata/​baselines/​reference/​compiler/​declarationEmitStripInternalTypeAliasRHS.symbols Records symbol baseline.
tsc/​testdata/​baselines/​reference/​compiler/​declarationEmitStripInternalTypeAliasRHS.types Records type baseline.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@github-project-automation github-project-automation Bot moved this from Not started to Needs merge in PR Backlog Oct 13, 2026
@jakebailey
Jake Bailey (jakebailey) added this pull request to the merge queue Oct 13, 2026
Merged via the queue into microsoft:main with commit 0a66074 Oct 13, 2026
29 checks passed
@github-project-automation github-project-automation Bot moved this from Needs merge to Done in PR Backlog Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

runtime error: invalid memory address or nil pointer dereference

3 participants