fix: Incorrect report of self-referencing type for static fields#63521
Closed
arnavnagzirkar wants to merge 1 commit into
Closed
fix: Incorrect report of self-referencing type for static fields#63521arnavnagzirkar wants to merge 1 commit into
arnavnagzirkar wants to merge 1 commit into
Conversation
Member
|
This doesn't meet the 6.0 patch bar. See #62963 (comment) I'm curious how you invoked Copilot; it should have warned you about this. ref. https://github.com/microsoft/TypeScript/blob/main/AGENTS.md#-do-not-create-coding-prs-for-this-repository |
This was referenced Jun 1, 2026
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 a class expression is passed to a generic function (e.g.,
id(class { static foo = id(42) })), TypeScript's type inference evaluates the contextual type for static property initializers. The call chain is:foopushesfooonto the type resolution stack.foo's initializer (id(42)), TypeScript computes its contextual type viagetContextualTypeForStaticPropertyDeclaration.getContextualTypeon the parent class expression, which is an argument to the outer generic call.getContextualTypeForArgumentAtIndexresolves the outer call's signature (which is already in theresolvingSignaturestate).getTypeOfConcretePropertyOfContextualTypeis called for propertyfooof the contextual type.getTypeOfSymbol(foo_symbol)→getTypeOfVariableOrParameterOrProperty(foo_symbol).pushTypeResolution(foo, Type)is called whilefoois already on the resolution stack — but hidden behindresolutionStart(reset bygetResolvedSignature). The lookup seesfooas a circular reference and falsely reports TS7022.The key issue:
getResolvedSignatureresetsresolutionStartto prevent false circularity errors in outer resolutions, but this also hidesfoo's in-progress resolution fromgetTypeOfConcretePropertyOfContextualType. When the contextual type lookup retries resolvingfoo's type,fooappears circular.Change Made
Added
isSymbolTypeResolutionInProgressfunction that checks the entire resolution stack (ignoringresolutionStart) to detect whether a symbol's type is currently being resolved.In
getTypeOfConcretePropertyOfContextualType, before callinggetTypeOfSymbol(prop), we now check if the property's type resolution is already in progress. If so, we returnundefined(no contextual type) rather than triggering a false circularity error.Files changed:
src/compiler/checker.ts: AddedisSymbolTypeResolutionInProgressfunction and used it ingetTypeOfConcretePropertyOfContextualType(lines ~11515–11525, ~32467–32473)tests/cases/compiler/staticFieldInClassExpressionPassedToGenericFunction.ts: New compiler testtests/baselines/reference/staticFieldInClassExpressionPassedToGenericFunction.{js,symbols,types}: BaselinesIssue
Fixes #62552
Issue URL: #62552
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.