fix: silentNeverType leak in contextual parameter types coming from anon...#63519
Closed
arnavnagzirkar wants to merge 2 commits into
Closed
fix: silentNeverType leak in contextual parameter types coming from anon...#63519arnavnagzirkar wants to merge 2 commits into
silentNeverType leak in contextual parameter types coming from anon...#63519arnavnagzirkar wants to merge 2 commits into
Conversation
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Root Cause
When an anonymous (non-aliased) object type like
{ default: T }is instantiated withT = silentNeverType(the placeholder used during inference), the resulting type{ default: never }does not get theObjectFlags.NonInferrableTypeflag — even though it containssilentNeverTypein its property type.This is inconsistent with:
P<T>):createTypeReferencecallsgetPropagatingFlagsOfTypes(typeArguments)to propagateNonInferrableTypefrom type arguments (line 16928).WithDefault<T>):instantiateAnonymousTypepropagates fromaliasTypeArguments(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) → hasNonInferrableType→ inference blocked →T_inner = unknown→ correct error{ default: silentNeverType }(anonymous) → missingNonInferrableType→ inference not blocked →T_inner = { default: silentNeverType }→ no error (inconsistent)This caused
foo1,foo4, andfoo5to silently succeed whilefoo2andfoo3correctly produced errors. Additionally,foo2/foo3'sresolvewas typed as(value: never) => void(the leakedsilentNeverType) instead of(value: unknown) => void.Change Made
File:
src/compiler/checker.tsIn
getObjectTypeInstantiation(around line 20786), after the anonymous type instantiation result is stored in the cache, added propagation ofNonInferrableTypefromtypeArgumentsfor anonymous types that don't havealiasTypeArguments:The condition
!newAliasTypeArgumentsensures we only add the propagation for truly anonymous (non-alias) types, since the alias case is already handled insideinstantiateAnonymousTypeviaaliasTypeArguments.Issue
Fixes #62345
Issue URL: #62345
Changes
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.