1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
tests/cases/conformance/types/thisType/unionThisTypeInFunctions.ts(10,5): error TS2684: The 'this' context of type 'Real | Fake' is not assignable to method's 'this' of type 'Real & Fake'.
Type 'Real' is not assignable to type 'Real & Fake'.
Type 'Real' is not assignable to type 'Fake'.
Types of property 'method' are incompatible.
Type '(this: Real, n: number) => void' is not assignable to type '(this: Fake, n: number) => void'.
The 'this' types of each signature are incompatible.
Type 'Fake' is not assignable to type 'Real'.
Types of property 'data' are incompatible.
Type 'number' is not assignable to type 'string'.
==== tests/cases/conformance/types/thisType/unionThisTypeInFunctions.ts (1 errors) ====
interface Real {
method(this: this, n: number): void;
data: string;
}
interface Fake {
method(this: this, n: number): void;
data: number;
}
function test(r: Real | Fake) {
r.method(12); // error
~
!!! error TS2684: The 'this' context of type 'Real | Fake' is not assignable to method's 'this' of type 'Real & Fake'.
!!! error TS2684: Type 'Real' is not assignable to type 'Real & Fake'.
!!! error TS2684: Type 'Real' is not assignable to type 'Fake'.
!!! error TS2684: Types of property 'method' are incompatible.
!!! error TS2684: Type '(this: Real, n: number) => void' is not assignable to type '(this: Fake, n: number) => void'.
!!! error TS2684: The 'this' types of each signature are incompatible.
!!! error TS2684: Type 'Fake' is not assignable to type 'Real'.
!!! error TS2684: Types of property 'data' are incompatible.
!!! error TS2684: Type 'number' is not assignable to type 'string'.
}
|