Uh oh!
There was an error while loading. Please reload this page.
Fixed local extends constraints of infer type parameters when they can contain type variables - #60345
Conversation
…can contain type variables
659c426 to
7cf0d7cCompare| function maybeCloneInferTypeParameter(p: TypeParameter) { | ||
| return getConstraintDeclaration(p) && couldContainTypeVariables(getConstraintFromTypeParameter(p)!) ? cloneTypeParameter(p) : p; | ||
| } |
There was a problem hiding this comment.
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)
seb (zedryas)
commented
Oct 28, 2024
thank you very much Mateusz Burzyński (@Andarist), how long do you reckon before this might be merged ? |
Mateusz Burzyński (Andarist)
commented
Oct 28, 2024
seb (@zedryas) that's not up to me, we have to wait for the review and merge by one of the TS team members |
Jake Bailey (jakebailey)
commented
Oct 28, 2024
TypeScript Bot (@typescript-bot) test it |
TypeScript Bot (typescript-bot)
commented
Oct 28, 2024
Jake Bailey (@jakebailey) Here are the results of running the user tests with tsc comparing Everything looks good! |
TypeScript Bot (typescript-bot)
commented
Oct 28, 2024
Hey Jake Bailey (@jakebailey), the results of running the DT tests are ready. Everything looks the same! |
TypeScript Bot (typescript-bot)
commented
Oct 28, 2024
Jake Bailey (@jakebailey) Here they are:tscComparison Report - baseline..pr
System info unknown Hosts
Scenarios
Developer Information: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TypeScript Bot (typescript-bot)
commented
Oct 28, 2024
Jake Bailey (@jakebailey) Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
seb (zedryas)
commented
Dec 13, 2024
Any update on this merge request? cc Wesley Wigham (@weswigham) (i do tag because you were the reviewer on #57362 ) |
TypeScript Bot (typescript-bot)
commented
Mar 24, 2026
With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies). Next steps for PRs:
|
fixes#60299
this reverts a good chunk of #57362 but it also makes some modifications to the code that was removed there
cc Wesley Wigham (@weswigham)