File: typeRelationships.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 (56 lines) | stat: -rw-r--r-- 2,435 bytes parent folder | download | duplicates (4)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
tests/cases/conformance/types/thisType/typeRelationships.ts(9,9): error TS2322: Type 'C' is not assignable to type 'this'.
  'C' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'C'.
tests/cases/conformance/types/thisType/typeRelationships.ts(35,9): error TS2739: Type 'C' is missing the following properties from type 'D': self1, self2, self3, d, bar
tests/cases/conformance/types/thisType/typeRelationships.ts(36,9): error TS2322: Type 'D' is not assignable to type 'this'.
  'D' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'D'.


==== tests/cases/conformance/types/thisType/typeRelationships.ts (3 errors) ====
    class C {
        self = this;
        c = new C();
        foo() {
            return this;
        }
        f1() {
            this.c = this.self;
            this.self = this.c;  // Error
            ~~~~~~~~~
!!! error TS2322: Type 'C' is not assignable to type 'this'.
!!! error TS2322:   'C' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'C'.
        }
        f2() {
            var a: C[];
            var a = [this, this.c];  // C[] since this is subtype of C
            var b: this[];
            var b = [this, this.self, null, undefined];
        }
        f3(b: boolean) {
            return b ? this.c : this.self;  // Should be C
        }
    }
    
    class D extends C {
        self1 = this;
        self2 = this.self;
        self3 = this.foo();
        d = new D();
        bar() {
            this.self = this.self1;
            this.self = this.self2;
            this.self = this.self3;
            this.self1 = this.self;
            this.self2 = this.self;
            this.self3 = this.self;
            this.d = this.self;
            this.d = this.c;  // Error
            ~~~~~~
!!! error TS2739: Type 'C' is missing the following properties from type 'D': self1, self2, self3, d, bar
            this.self = this.d;  // Error
            ~~~~~~~~~
!!! error TS2322: Type 'D' is not assignable to type 'this'.
!!! error TS2322:   'D' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'D'.
            this.c = this.d;
        }
    }