-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Avoid resolving source prop type when the target is unknown
/any
#61660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Avoid resolving source prop type when the target is unknown
/any
#61660
Conversation
c5da502
to
8289db7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR improves the performance and accuracy of type checking for property symbols by short‐circuiting the relation check when the target type is “any” (or “any”/“unknown” when not using strict subtype relation).
- Introduces a new condition in isPropertySymbolTypeRelated that returns Ternary.True when the effective target’s flags indicate “any” (or “any”/“unknown” depending on the relation), thereby avoiding unnecessary resolution of the source property type.
- Adds an explanatory comment to document this behavior per issue Support cyclical type inference of self-referential data structures, when subject to some assignability constraints #61659.
Files not reviewed (5)
- tests/baselines/reference/multiline.types: Language not supported
- tests/baselines/reference/noCircularitySelfReferentialGetter1.symbols: Language not supported
- tests/baselines/reference/noCircularitySelfReferentialGetter1.types: Language not supported
- tests/baselines/reference/noCircularitySelfReferentialGetter2.symbols: Language not supported
- tests/baselines/reference/noCircularitySelfReferentialGetter2.types: Language not supported
@@ -24057,6 +24057,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |||
function isPropertySymbolTypeRelated(sourceProp: Symbol, targetProp: Symbol, getTypeOfSourceProperty: (sym: Symbol) => Type, reportErrors: boolean, intersectionState: IntersectionState): Ternary { | |||
const targetIsOptional = strictNullChecks && !!(getCheckFlags(targetProp) & CheckFlags.Partial); | |||
const effectiveTarget = addOptionality(getNonMissingTypeOfSymbol(targetProp), /*isProperty*/ false, targetIsOptional); | |||
// source could resolve to `any` and that's not related to `unknown` target under strict subtype relation | |||
if (effectiveTarget.flags & (relation === strictSubtypeRelation ? TypeFlags.Any : TypeFlags.AnyOrUnknown)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition now short-circuits the type relation check when the target type is 'any' (or 'any'/'unknown' depending on the relation), which is the intended behavior per issue #61659. Consider adding a reference to the issue number in the comment for clearer context and future maintainability.
Copilot uses AI. Check for mistakes.
8289db7
to
540e84d
Compare
I will just pop in here to note that this would presumably hep with a number of circularities I've experienced. |
closes #61659