Skip to content

fix: silentNeverType leak in contextual parameter types coming from anon...#63519

Closed
arnavnagzirkar wants to merge 2 commits into
microsoft:mainfrom
arnavnagzirkar:fix-62345
Closed

fix: silentNeverType leak in contextual parameter types coming from anon...#63519
arnavnagzirkar wants to merge 2 commits into
microsoft:mainfrom
arnavnagzirkar:fix-62345

Conversation

@arnavnagzirkar
Copy link
Copy Markdown

Summary

Root Cause

When an anonymous (non-aliased) object type like { default: T } is instantiated with T = silentNeverType (the placeholder used during inference), the resulting type { default: never } does not get the ObjectFlags.NonInferrableType flag — even though it contains silentNeverType in its property type.

This is inconsistent with:

  • Type references (P<T>): createTypeReference calls getPropagatingFlagsOfTypes(typeArguments) to propagate NonInferrableType from type arguments (line 16928).
  • Anonymous types with a type alias (WithDefault<T>): instantiateAnonymousType propagates from aliasTypeArguments (line 20984).

For anonymous types without a type alias (plain object type literals like { default: T }), neither of these propagation paths applied. As a result:

  • WithDefault<silentNeverType> (type alias) → has NonInferrableType → inference blocked → T_inner = unknown → correct error
  • { default: silentNeverType } (anonymous) → missing NonInferrableType → inference not blocked → T_inner = { default: silentNeverType } → no error (inconsistent)

This caused foo1, foo4, and foo5 to silently succeed while foo2 and foo3 correctly produced errors. Additionally, foo2/foo3's resolve was typed as (value: never) => void (the leaked silentNeverType) instead of (value: unknown) => void.

Change Made

File: src/compiler/checker.ts

In getObjectTypeInstantiation (around line 20786), after the anonymous type instantiation result is stored in the cache, added propagation of NonInferrableType from typeArguments for anonymous types that don't have aliasTypeArguments:

// For anonymous types without aliasTypeArguments, propagate NonInferrableType from the type arguments.
// For types with aliasTypeArguments, instantiateAnonymousType already propagates this from aliasTypeArguments.
if (!(target.objectFlags & (ObjectFlags.Reference | ObjectFlags.Mapped)) && !newAliasTypeArguments) {
    (result as ObjectFlagsType).objectFlags |= getPropagatingFlagsOfTypes(typeArguments) & ObjectFlags.NonInferrableType;
}

The condition !newAliasTypeArguments ensures we only add the propagation for truly anonymous (non-alias) types, since the alias case is already handled inside instantiateAnonymousType via aliasTypeArguments.

Issue

Fixes #62345

Issue URL: #62345

Changes

AGENTS.md                                          |  69 ++++---
 src/compiler/checker.ts                            |   5 +
 ...ilentNeverAnonymousTypeNonInferrable.errors.txt |  94 +++++++++
 .../silentNeverAnonymousTypeNonInferrable.js       |  90 +++++++++
 .../silentNeverAnonymousTypeNonInferrable.symbols  | 156 +++++++++++++++
 .../silentNeverAnonymousTypeNonInferrable.types    | 210 +++++++++++++++++++++
 .../silentNeverAnonymousTypeNonInferrable.ts       |  57 ++++++
 7 files changed, 651 insertions(+), 30 deletions(-)

Testing

  • Agent ran relevant tests during development

  • Linting checks passed

  • Changes are minimal and focused on the issue

AI Assistance Disclosure

This PR was authored with the assistance of AI coding tools (GitHub Copilot). I have read and understand the change and will respond to review feedback myself.

Copilot AI review requested due to automatic review settings June 1, 2026 03:17
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Jun 1, 2026
@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Jun 1, 2026
@RyanCavanaugh
Copy link
Copy Markdown
Member

#63521 (comment)

@github-project-automation github-project-automation Bot moved this from Not started to Done in PR Backlog Jun 1, 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.

silentNeverType leak in contextual parameter types coming from anonymous non-aliased object type instantiations

3 participants