-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Instantiate original target type in substituteIndexedMappedType #49205
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
Conversation
@@ -15798,7 +15798,7 @@ namespace ts { | |||
function substituteIndexedMappedType(objectType: MappedType, index: Type) { | |||
const mapper = createTypeMapper([getTypeParameterFromMappedType(objectType)], [index]); | |||
const templateMapper = combineTypeMappers(objectType.mapper, mapper); | |||
return instantiateType(getTemplateTypeFromMappedType(objectType), templateMapper); | |||
return instantiateType(getTemplateTypeFromMappedType(objectType.target as MappedType || objectType), templateMapper); |
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.
Is .target
like a "link" to the original type if you end up creating a new instantiated type from something? 🤔 Would in such a case first "call" to this lack the .target
but all future calls would be able to use it?
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.
Yes, an instantiated type has a target
property that links to the original mapped type and a mapper
property that provides a mapping from type parameters to corresponding type arguments. The original mapped type doesn't have target
and mapper
properties. It's target is itself and it's type parameters are also its type arguments, so to speak.
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.
Should getTemplateTypeFromMappedType
just always look up the .target
and it's template first?
It could, but it would just add another code path and not save anything. |
I just bring it up because only about half the callers do this target following right now, and I'm unsure if the other half should be, as a rule. |
No tests in this PR as it only affects performance. Have manually verified that issue in #49136 is gone (we go from >4M instantiations to just 172 when compiling the original example).
Fixes #49136.