File: looseThisTypeInFunctions.errors.txt

package info (click to toggle)
node-typescript 2.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 203,952 kB
  • ctags: 52,987
  • sloc: sh: 11; makefile: 5
file content (67 lines) | stat: -rw-r--r-- 3,073 bytes parent folder | download | duplicates (2)
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
57
58
59
60
61
62
63
64
65
66
67
tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts(21,1): error TS2322: Type '(this: C, m: number) => number' is not assignable to type '(this: void, m: number) => number'.
  The 'this' types of each signature are incompatible.
    Type 'void' is not assignable to type 'C'.
tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts(33,28): error TS2339: Property 'length' does not exist on type 'number'.
tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts(37,9): error TS2684: The 'this' context of type 'void' is not assignable to method's 'this' of type 'I'.
tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts(46,20): error TS2339: Property 'length' does not exist on type 'number'.


==== tests/cases/conformance/types/thisType/looseThisTypeInFunctions.ts (4 errors) ====
    interface I {
        n: number;
        explicitThis(this: this, m: number): number;
    }
    interface Unused {
        implicitNoThis(m: number): number;
    }
    class C implements I {
        n: number;
        explicitThis(this: this, m: number): number {
            return this.n + m;
        }
        implicitThis(m: number): number {
            return this.n + m;
        }
        explicitVoid(this: void, m: number): number {
            return m + 1;
        }
    }
    let c = new C();
    c.explicitVoid = c.explicitThis; // error, 'void' is missing everything
    ~~~~~~~~~~~~~~
!!! error TS2322: Type '(this: C, m: number) => number' is not assignable to type '(this: void, m: number) => number'.
!!! error TS2322:   The 'this' types of each signature are incompatible.
!!! error TS2322:     Type 'void' is not assignable to type 'C'.
    let o = {
        n: 101,
        explicitThis: function (m: number) {
            return m + this.n.length; // error, 'length' does not exist on 'number'
        },
        implicitThis(m: number): number { return m; }
    };
    let i: I = o;
    let o2: I = {
        n: 1001,
        explicitThis: function (m) {
             return m + this.n.length;  // error, this.n: number, no member 'length'
                               ~~~~~~
!!! error TS2339: Property 'length' does not exist on type 'number'.
        },
    }
    let x = i.explicitThis;
    let n = x(12); // callee:void doesn't match this:I
            ~~~~~
!!! error TS2684: The 'this' context of type 'void' is not assignable to method's 'this' of type 'I'.
    let u: Unused;
    let y = u.implicitNoThis;
    n = y(12); // ok, callee:void matches this:any
    c.explicitVoid = c.implicitThis // ok, implicitThis(this:any)
    o.implicitThis = c.implicitThis; // ok, implicitThis(this:any)
    o.implicitThis = c.explicitThis; // ok, implicitThis(this:any) is assignable to explicitThis(this: this)
    o.implicitThis = i.explicitThis;
    i.explicitThis = function(m) {
         return this.n.length;  // error, this.n: number
                       ~~~~~~
!!! error TS2339: Property 'length' does not exist on type 'number'.
    }