File: unionThisTypeInFunctions.errors.txt

package info (click to toggle)
node-typescript 4.8.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 523,068 kB
  • sloc: javascript: 1,735,777; makefile: 7; sh: 1
file content (42 lines) | stat: -rw-r--r-- 2,602 bytes parent folder | download | duplicates (3)
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
35
36
37
38
39
40
41
42
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 'method' are incompatible.
                Type '(this: Fake, n: number) => void' is not assignable to type '(this: Real, n: number) => void'.
                  The 'this' types of each signature are incompatible.
                    Type 'Real' is not assignable to type 'Fake'.
                      Types of property 'data' are incompatible.
                        Type 'string' is not assignable to type 'number'.


==== 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 'method' are incompatible.
!!! error TS2684:                 Type '(this: Fake, n: number) => void' is not assignable to type '(this: Real, n: number) => void'.
!!! error TS2684:                   The 'this' types of each signature are incompatible.
!!! error TS2684:                     Type 'Real' is not assignable to type 'Fake'.
!!! error TS2684:                       Types of property 'data' are incompatible.
!!! error TS2684:                         Type 'string' is not assignable to type 'number'.
    }