File: unionThisTypeInFunctions.errors.txt

package info (click to toggle)
node-typescript 5.0.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 459,140 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (34 lines) | stat: -rw-r--r-- 1,866 bytes parent folder | download
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'.
    }