mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge pull request #7290 from Microsoft/thisTypesInBasePropAndContainer
Feed the 'this' type as a type argument to constraints during relation checking
This commit is contained in:
@@ -5906,9 +5906,14 @@ namespace ts {
|
||||
|
||||
if (source.flags & TypeFlags.TypeParameter) {
|
||||
let constraint = getConstraintOfTypeParameter(<TypeParameter>source);
|
||||
|
||||
if (!constraint || constraint.flags & TypeFlags.Any) {
|
||||
constraint = emptyObjectType;
|
||||
}
|
||||
|
||||
// The constraint may need to be further instantiated with its 'this' type.
|
||||
constraint = getTypeWithThisArgument(constraint, source);
|
||||
|
||||
// Report constraint errors only if the constraint is not the empty object type
|
||||
const reportConstraintErrors = reportErrors && constraint !== emptyObjectType;
|
||||
if (result = isRelatedTo(constraint, target, reportConstraintErrors)) {
|
||||
|
||||
@@ -4,7 +4,6 @@ tests/cases/compiler/fuzzy.ts(21,20): error TS2322: Type '{ anything: number; on
|
||||
Types of property 'oneI' are incompatible.
|
||||
Type 'this' is not assignable to type 'I'.
|
||||
Type 'C' is not assignable to type 'I'.
|
||||
Property 'alsoWorks' is missing in type 'C'.
|
||||
tests/cases/compiler/fuzzy.ts(25,20): error TS2352: Type '{ oneI: this; }' cannot be converted to type 'R'.
|
||||
Property 'anything' is missing in type '{ oneI: this; }'.
|
||||
|
||||
@@ -39,7 +38,6 @@ tests/cases/compiler/fuzzy.ts(25,20): error TS2352: Type '{ oneI: this; }' canno
|
||||
!!! error TS2322: Types of property 'oneI' are incompatible.
|
||||
!!! error TS2322: Type 'this' is not assignable to type 'I'.
|
||||
!!! error TS2322: Type 'C' is not assignable to type 'I'.
|
||||
!!! error TS2322: Property 'alsoWorks' is missing in type 'C'.
|
||||
}
|
||||
|
||||
worksToo():R {
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
//// [recurringTypeParamForContainerOfBase01.ts]
|
||||
|
||||
interface BoxOfFoo<T extends Foo<T>> {
|
||||
item: T
|
||||
}
|
||||
|
||||
interface Foo<T extends Foo<T>> {
|
||||
self: T;
|
||||
}
|
||||
|
||||
interface Bar<T extends Bar<T>> extends Foo<T> {
|
||||
other: BoxOfFoo<T>;
|
||||
}
|
||||
|
||||
//// [recurringTypeParamForContainerOfBase01.js]
|
||||
|
||||
|
||||
//// [recurringTypeParamForContainerOfBase01.d.ts]
|
||||
interface BoxOfFoo<T extends Foo<T>> {
|
||||
item: T;
|
||||
}
|
||||
interface Foo<T extends Foo<T>> {
|
||||
self: T;
|
||||
}
|
||||
interface Bar<T extends Bar<T>> extends Foo<T> {
|
||||
other: BoxOfFoo<T>;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
=== tests/cases/conformance/types/typeParameters/recurringTypeParamForContainerOfBase01.ts ===
|
||||
|
||||
interface BoxOfFoo<T extends Foo<T>> {
|
||||
>BoxOfFoo : Symbol(BoxOfFoo, Decl(recurringTypeParamForContainerOfBase01.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 19))
|
||||
>Foo : Symbol(Foo, Decl(recurringTypeParamForContainerOfBase01.ts, 3, 1))
|
||||
>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 19))
|
||||
|
||||
item: T
|
||||
>item : Symbol(BoxOfFoo.item, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 38))
|
||||
>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 1, 19))
|
||||
}
|
||||
|
||||
interface Foo<T extends Foo<T>> {
|
||||
>Foo : Symbol(Foo, Decl(recurringTypeParamForContainerOfBase01.ts, 3, 1))
|
||||
>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 14))
|
||||
>Foo : Symbol(Foo, Decl(recurringTypeParamForContainerOfBase01.ts, 3, 1))
|
||||
>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 14))
|
||||
|
||||
self: T;
|
||||
>self : Symbol(Foo.self, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 33))
|
||||
>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 5, 14))
|
||||
}
|
||||
|
||||
interface Bar<T extends Bar<T>> extends Foo<T> {
|
||||
>Bar : Symbol(Bar, Decl(recurringTypeParamForContainerOfBase01.ts, 7, 1))
|
||||
>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 14))
|
||||
>Bar : Symbol(Bar, Decl(recurringTypeParamForContainerOfBase01.ts, 7, 1))
|
||||
>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 14))
|
||||
>Foo : Symbol(Foo, Decl(recurringTypeParamForContainerOfBase01.ts, 3, 1))
|
||||
>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 14))
|
||||
|
||||
other: BoxOfFoo<T>;
|
||||
>other : Symbol(Bar.other, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 48))
|
||||
>BoxOfFoo : Symbol(BoxOfFoo, Decl(recurringTypeParamForContainerOfBase01.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(recurringTypeParamForContainerOfBase01.ts, 9, 14))
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
=== tests/cases/conformance/types/typeParameters/recurringTypeParamForContainerOfBase01.ts ===
|
||||
|
||||
interface BoxOfFoo<T extends Foo<T>> {
|
||||
>BoxOfFoo : BoxOfFoo<T>
|
||||
>T : T
|
||||
>Foo : Foo<T>
|
||||
>T : T
|
||||
|
||||
item: T
|
||||
>item : T
|
||||
>T : T
|
||||
}
|
||||
|
||||
interface Foo<T extends Foo<T>> {
|
||||
>Foo : Foo<T>
|
||||
>T : T
|
||||
>Foo : Foo<T>
|
||||
>T : T
|
||||
|
||||
self: T;
|
||||
>self : T
|
||||
>T : T
|
||||
}
|
||||
|
||||
interface Bar<T extends Bar<T>> extends Foo<T> {
|
||||
>Bar : Bar<T>
|
||||
>T : T
|
||||
>Bar : Bar<T>
|
||||
>T : T
|
||||
>Foo : Foo<T>
|
||||
>T : T
|
||||
|
||||
other: BoxOfFoo<T>;
|
||||
>other : BoxOfFoo<T>
|
||||
>BoxOfFoo : BoxOfFoo<T>
|
||||
>T : T
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//// [thisTypeInBasePropertyAndDerivedContainerOfBase01.ts]
|
||||
|
||||
interface BoxOfFoo<T extends Foo> {
|
||||
item: T
|
||||
}
|
||||
|
||||
interface Foo {
|
||||
self: this;
|
||||
}
|
||||
|
||||
interface Bar extends Foo {
|
||||
other: BoxOfFoo<this>;
|
||||
}
|
||||
|
||||
//// [thisTypeInBasePropertyAndDerivedContainerOfBase01.js]
|
||||
|
||||
|
||||
//// [thisTypeInBasePropertyAndDerivedContainerOfBase01.d.ts]
|
||||
interface BoxOfFoo<T extends Foo> {
|
||||
item: T;
|
||||
}
|
||||
interface Foo {
|
||||
self: this;
|
||||
}
|
||||
interface Bar extends Foo {
|
||||
other: BoxOfFoo<this>;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
=== tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts ===
|
||||
|
||||
interface BoxOfFoo<T extends Foo> {
|
||||
>BoxOfFoo : Symbol(BoxOfFoo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 1, 19))
|
||||
>Foo : Symbol(Foo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 3, 1))
|
||||
|
||||
item: T
|
||||
>item : Symbol(BoxOfFoo.item, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 1, 35))
|
||||
>T : Symbol(T, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 1, 19))
|
||||
}
|
||||
|
||||
interface Foo {
|
||||
>Foo : Symbol(Foo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 3, 1))
|
||||
|
||||
self: this;
|
||||
>self : Symbol(Foo.self, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 5, 15))
|
||||
}
|
||||
|
||||
interface Bar extends Foo {
|
||||
>Bar : Symbol(Bar, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 7, 1))
|
||||
>Foo : Symbol(Foo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 3, 1))
|
||||
|
||||
other: BoxOfFoo<this>;
|
||||
>other : Symbol(Bar.other, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 9, 27))
|
||||
>BoxOfFoo : Symbol(BoxOfFoo, Decl(thisTypeInBasePropertyAndDerivedContainerOfBase01.ts, 0, 0))
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
=== tests/cases/conformance/types/thisType/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts ===
|
||||
|
||||
interface BoxOfFoo<T extends Foo> {
|
||||
>BoxOfFoo : BoxOfFoo<T>
|
||||
>T : T
|
||||
>Foo : Foo
|
||||
|
||||
item: T
|
||||
>item : T
|
||||
>T : T
|
||||
}
|
||||
|
||||
interface Foo {
|
||||
>Foo : Foo
|
||||
|
||||
self: this;
|
||||
>self : this
|
||||
}
|
||||
|
||||
interface Bar extends Foo {
|
||||
>Bar : Bar
|
||||
>Foo : Foo
|
||||
|
||||
other: BoxOfFoo<this>;
|
||||
>other : BoxOfFoo<this>
|
||||
>BoxOfFoo : BoxOfFoo<T>
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// @declaration: true
|
||||
|
||||
interface BoxOfFoo<T extends Foo> {
|
||||
item: T
|
||||
}
|
||||
|
||||
interface Foo {
|
||||
self: this;
|
||||
}
|
||||
|
||||
interface Bar extends Foo {
|
||||
other: BoxOfFoo<this>;
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// @declaration: true
|
||||
|
||||
interface BoxOfFoo<T extends Foo<T>> {
|
||||
item: T
|
||||
}
|
||||
|
||||
interface Foo<T extends Foo<T>> {
|
||||
self: T;
|
||||
}
|
||||
|
||||
interface Bar<T extends Bar<T>> extends Foo<T> {
|
||||
other: BoxOfFoo<T>;
|
||||
}
|
||||
Reference in New Issue
Block a user