Skip to content

Commit 5f782bf

Browse files
authored
Fixup restrictive instantiations to actually erase type parameter constraints (#29592)
1 parent bd8c625 commit 5f782bf

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10636,7 +10636,11 @@ namespace ts {
1063610636
}
1063710637

1063810638
function getRestrictiveTypeParameter(tp: TypeParameter) {
10639-
return !tp.constraint ? tp : tp.restrictiveInstantiation || (tp.restrictiveInstantiation = createTypeParameter(tp.symbol));
10639+
return tp.constraint === unknownType ? tp : tp.restrictiveInstantiation || (
10640+
tp.restrictiveInstantiation = createTypeParameter(tp.symbol),
10641+
(tp.restrictiveInstantiation as TypeParameter).constraint = unknownType,
10642+
tp.restrictiveInstantiation
10643+
);
1064010644
}
1064110645

1064210646
function restrictiveMapper(type: Type) {

tests/baselines/reference/typeParameterIndirectlyConstrainedToItself.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterInd
2525
tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts(16,47): error TS2313: Type parameter 'V' has a circular constraint.
2626
tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts(18,32): error TS2313: Type parameter 'T' has a circular constraint.
2727
tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts(18,45): error TS2313: Type parameter 'V' has a circular constraint.
28-
tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts(23,24): error TS2313: Type parameter 'S' has a circular constraint.
2928

3029

31-
==== tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts (28 errors) ====
30+
==== tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts (27 errors) ====
3231
class C<U extends T, T extends U> { }
3332
~
3433
!!! error TS2313: Type parameter 'U' has a circular constraint.
@@ -106,6 +105,4 @@ tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterInd
106105

107106
type Foo<T> = [T] extends [number] ? {} : {};
108107
function foo<S extends Foo<S>>() {}
109-
~~~~~~
110-
!!! error TS2313: Type parameter 'S' has a circular constraint.
111108

tests/baselines/reference/typeParameterIndirectlyConstrainedToItself.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ type Foo<T> = [T] extends [number] ? {} : {};
3838
>Foo : Foo<T>
3939

4040
function foo<S extends Foo<S>>() {}
41-
>foo : <S>() => void
41+
>foo : <S extends Foo<S>>() => void
4242

0 commit comments

Comments
 (0)