-
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
Fixed symbol declarations for generic filtering mapped types #53207
Fixed symbol declarations for generic filtering mapped types #53207
Conversation
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
@@ -13174,8 +13174,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |||
// and T as the template type. | |||
const typeParameter = getTypeParameterFromMappedType(type); | |||
const constraintType = getConstraintTypeFromMappedType(type); | |||
const nameType = getNameTypeFromMappedType(type.target as MappedType || type); | |||
const isFilteringMappedType = nameType && isTypeAssignableTo(nameType, typeParameter); |
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 bug was here, this likely should have been something like this:
-const isFilteringMappedType = nameType && isTypeAssignableTo(nameType, typeParameter);
+const isFilteringMappedType = nameType && isTypeAssignableTo(nameType, getTypeParameterFromMappedType(type.target as MappedType || type));
and this is what happens in the added isFilteringMappedType
since it unpacks the correct mapped type on its own and uses it as the source of information for both arguments passed to isTypeAssignableTo
Is this something we might want to cherry-pick into a 5.0 patch? |
I would love for it to happen. The original intention was to make this work - it's just a silly bug that slipped our eyes. |
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.
Looks like a fine fix. I have a small style nit, since you extracted some stuff into a constant anyway. TBD what patch we'll pull this in to, but probably a 5.0.3, since this is a bit late for 5.0.2.
const isFilteringMappedType = nameType && isTypeAssignableTo(nameType, typeParameter); | ||
const mappedType = (type.target as MappedType) || type; | ||
const nameType = getNameTypeFromMappedType(mappedType); | ||
const shouldLinkPropDeclarations = !nameType || isFilteringMappedType(mappedType); | ||
const templateType = getTemplateTypeFromMappedType(type.target as MappedType || 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.
This line should also just reference mappedType
now.
@weswigham @jakebailey what’s the process of cherry-picking this into 5.0.3? Is this something that you will consider for this fix? |
The process is: @typescript-bot cherry-pick this to release-5.0 And we can discuss / merge it once 5.0.2 is out. |
Heya @jakebailey, I've started to run the task to cherry-pick this into |
Hey @jakebailey, I've opened #53271 for you. |
…e-5.0 (#53271) Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
…to release-5.0 (microsoft#53271) Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
the issue was noticed here
this PR is basically a fix for an unnoticed bug in the feature implemented in #51650 , the implementation itself is just a pulled-out refactor from #52972 since it (accidentally) fixed this issue
cc @sandersn @weswigham (reviewers of my original PR)