-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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 local extends
constraints of infer type parameters when they can contain type variables
#60345
base: main
Are you sure you want to change the base?
Conversation
…can contain type variables
659c426
to
7cf0d7c
Compare
function maybeCloneInferTypeParameter(p: TypeParameter) { | ||
return getConstraintDeclaration(p) && couldContainTypeVariables(getConstraintFromTypeParameter(p)!) ? cloneTypeParameter(p) : p; | ||
} |
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 only clones type parameters with "local" constraints (the ones added by infer R extends C
syntax)
It could do the same with all constraints, using this patch:
git diff
diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts
index a8803f5823..52f44bcebe 100644
--- a/src/compiler/checker.ts
+++ b/src/compiler/checker.ts
@@ -19117,9 +19117,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
}
const context = createInferenceContext(freshParams, /*signature*/ undefined, InferenceFlags.None);
- if (mapper) {
- context.nonFixingMapper = combineTypeMappers(context.nonFixingMapper, mapper);
- }
if (!checkTypeDeferred) {
// We don't want inferences from constraints as they may cause us to eagerly resolve the
// conditional type instead of deferring resolution. Also, we always want strict function
@@ -19220,7 +19217,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
function maybeCloneInferTypeParameter(p: TypeParameter) {
- return getConstraintDeclaration(p) && couldContainTypeVariables(getConstraintFromTypeParameter(p)!) ? cloneTypeParameter(p) : p;
+ const constraint = getConstraintFromTypeParameter(p);
+ return constraint && couldContainTypeVariables(constraint) ? cloneTypeParameter(p) : p;
}
function getTrueTypeFromConditionalType(type: ConditionalType) {
diff --git a/tests/baselines/reference/inferTypes1.types b/tests/baselines/reference/inferTypes1.types
index edc97a2ea1..f6018d54a3 100644
--- a/tests/baselines/reference/inferTypes1.types
+++ b/tests/baselines/reference/inferTypes1.types
@@ -1,5 +1,8 @@
//// [tests/cases/conformance/types/conditional/inferTypes1.ts] ////
+=== Performance Stats ===
+Instantiation count: 1,000
+
=== inferTypes1.ts ===
type Unpacked<T> =
>Unpacked : Unpacked<T>
As we can see, we could drop the context.nonFixingMapper
manipulation and simplify the logic here - but that would create more type parameter clones and that's even caught by this diff (Instantiation count was reported by one of the tests when using this patch)
thank you very much @Andarist, how long do you reckon before this might be merged ? |
@zedryas that's not up to me, we have to wait for the review and merge by one of the TS team members |
@typescript-bot test it |
@jakebailey Here are the results of running the user tests with tsc comparing Everything looks good! |
Hey @jakebailey, the results of running the DT tests are ready. Everything looks the same! |
@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! |
Any update on this merge request? cc @weswigham (i do tag because you were the reviewer on #57362 ) |
fixes #60299
this reverts a good chunk of #57362 but it also makes some modifications to the code that was removed there
cc @weswigham