Skip to content

Comments

Fix startup crash when redefining global Array with @noLib#63179

Open
hayatexe wants to merge 1 commit intomicrosoft:mainfrom
hayatexe:fix-nolib-array-crash
Open

Fix startup crash when redefining global Array with @noLib#63179
hayatexe wants to merge 1 commit intomicrosoft:mainfrom
hayatexe:fix-nolib-array-crash

Conversation

@hayatexe
Copy link

Fixes #57009

Description
When --noLib is specified and a user statically re-defines Array through a generic type alias (e.g. type Array<T> = T[]), attempting to build the program causes the compiler to hit a crash early in the startup phase.

The issue occurred because the globalArrayType is resolved dynamically via getGlobalType. In --noLib scenarios, the alias for Array matches the global type, invoking type resolution to load the Array's target type before globalArrayType has finished initializing. When evaluating T[], getArrayOrTupleTargetType is called and tries to return globalArrayType (which is still undefined). This caused target inside getTypeFromArrayOrTupleTypeNode to be undefined, which subsequently crashed on createDeferredTypeReference(target, ...) because it accessed target.symbol.

This PR fixes the crash by explicitly letting getArrayOrTupleTargetType fallback to emptyGenericType instead of returning undefined. This resolves the dependency cycle cleanly and causes the checker to produce expected diagnostic errors (Global type 'Array' must have 1 type parameter(s)) instead of crashing the process.

A regression test is included.

@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Feb 22, 2026
@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Feb 22, 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: Not started

Development

Successfully merging this pull request may close these issues.

Crash when defining Array type via [] syntax

2 participants