Fixup restrictive instantiations to actually erase type parameter constraints (#29592)

This commit is contained in:
Wesley Wigham 2019-01-25 15:18:07 -08:00 committed by GitHub
parent bd8c6259b9
commit 5f782bf58a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 6 deletions

View file

@ -10636,7 +10636,11 @@ namespace ts {
}
function getRestrictiveTypeParameter(tp: TypeParameter) {
return !tp.constraint ? tp : tp.restrictiveInstantiation || (tp.restrictiveInstantiation = createTypeParameter(tp.symbol));
return tp.constraint === unknownType ? tp : tp.restrictiveInstantiation || (
tp.restrictiveInstantiation = createTypeParameter(tp.symbol),
(tp.restrictiveInstantiation as TypeParameter).constraint = unknownType,
tp.restrictiveInstantiation
);
}
function restrictiveMapper(type: Type) {

View file

@ -25,10 +25,9 @@ tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterInd
tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts(16,47): error TS2313: Type parameter 'V' has a circular constraint.
tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts(18,32): error TS2313: Type parameter 'T' has a circular constraint.
tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts(18,45): error TS2313: Type parameter 'V' has a circular constraint.
tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts(23,24): error TS2313: Type parameter 'S' has a circular constraint.
==== tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts (28 errors) ====
==== tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts (27 errors) ====
class C<U extends T, T extends U> { }
~
!!! error TS2313: Type parameter 'U' has a circular constraint.
@ -106,6 +105,4 @@ tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterInd
type Foo<T> = [T] extends [number] ? {} : {};
function foo<S extends Foo<S>>() {}
~~~~~~
!!! error TS2313: Type parameter 'S' has a circular constraint.

View file

@ -38,5 +38,5 @@ type Foo<T> = [T] extends [number] ? {} : {};
>Foo : Foo<T>
function foo<S extends Foo<S>>() {}
>foo : <S>() => void
>foo : <S extends Foo<S>>() => void