Skip to content

Fix crash when inferring from tuple with middle rest and trailing variadic elements#63288

Closed
ongjin wants to merge 1 commit intomicrosoft:mainfrom
ongjin:fix/crash-tuple-rest-variadic-inference
Closed

Fix crash when inferring from tuple with middle rest and trailing variadic elements#63288
ongjin wants to merge 1 commit intomicrosoft:mainfrom
ongjin:fix/crash-tuple-rest-variadic-inference

Conversation

@ongjin
Copy link

@ongjin ongjin commented Mar 24, 2026

Summary

Fixes #63005

When inferring from a tuple type that has middle rest elements and trailing variadic elements (e.g., [...(infer C)[], ...infer B extends [any, any, any]]), the compiler crashes with TypeError: Cannot read properties of undefined (reading 'aliasSymbol').

Root cause: getElementTypeOfSliceOfTupleType returns undefined when the implied arity from the variadic constraint consumes the entire source tuple, but the result was passed to inferFromTypes via a non-null assertion (!).

Fix: Add null checks before calling inferFromTypes in both the [...T, ...rest] and [...rest, ...T] inference branches, consistent with the existing pattern at the single-rest-element branch nearby.

Test plan

  • Added a test case to inferTypesWithFixedTupleExtendsAtVariadicPosition.ts that previously crashed
  • All existing variadic tuple inference tests continue to pass

…iadic elements

When `getElementTypeOfSliceOfTupleType` returns `undefined` (because the
implied arity from the variadic constraint consumes the entire source
tuple), the result was passed directly to `inferFromTypes` via a non-null
assertion, causing a `TypeError: Cannot read properties of undefined
(reading 'aliasSymbol')` crash.

Add null checks before calling `inferFromTypes` in both the `[...T, ...rest]`
and `[...rest, ...T]` inference branches, consistent with the existing
pattern used in the single-rest-element branch.

Fixes microsoft#63005
@ongjin
Copy link
Author

ongjin commented Mar 24, 2026

@microsoft-github-policy-service agree

@typescript-bot
Copy link
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.

Crash: when inferring from a tuple with middle rest elements and trailing variadic elements

2 participants