-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Unwrap substitution types early in getPropertyTypeForIndexType
#57113
base: main
Are you sure you want to change the base?
Unwrap substitution types early in getPropertyTypeForIndexType
#57113
Conversation
src/compiler/checker.ts
Outdated
@@ -16173,7 +16173,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |||
} | |||
|
|||
function getSubstitutionType(baseType: Type, constraint: Type) { | |||
return constraint.flags & TypeFlags.AnyOrUnknown || constraint === baseType || baseType.flags & TypeFlags.Any ? | |||
return constraint.flags & TypeFlags.AnyOrUnknown || constraint === baseType || baseType.flags & TypeFlags.Any || !isGenericType(constraint) && !isGenericType(baseType) && isTypeAssignableTo(baseType, constraint) ? |
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.
alternatively, substitution types could get some improved handling in getPropertyTypeForIndexType
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.
Yeah, I think I'd prefer getPropertyNameFromIndex
+ getPropertyTypeForIndexType
being updated to handle substitutions - the more places we recognize them as transparently their original type (if the substituted version isn't useful), the better, since it makes it easier on us to broaden the scope of how we use substitution types to support other features.
As far as this approach goes... instantiateTypeWorker
has similar logic to this - honestly, a lot of that logic should probably get moved into here, so it happens on initial construction and instantiation, rather than just instantiation.
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.
I agree, the right approach is to erase them where needed. Omitting the substitution type just because the constraint is assignable isn't right and will definitely have adverse effects as the constraint may be a more specific type.
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.
I pushed out the requested change. I decided to use a similar approach of unwrapping the substation type early in getPropertyTypeForIndexType
like it was done in #58292
getPropertyTypeForIndexType
@typescript-bot test it |
Hey @jakebailey, the results of running the DT tests are ready. Everything looks the same! |
@jakebailey Here are the results of running the user tests with tsc comparing Everything looks good! |
@jakebailey Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
@jakebailey Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
fixes #57109
fixes #54886