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
|
=== tests/cases/compiler/noImplicitThisFunctions.ts ===
function f1(x) {
>f1 : (x: any) => any
>x : any
// implicit any is still allowed
return x + 1;
>x + 1 : any
>x : any
>1 : 1
}
function f2(y: number) {
>f2 : (y: number) => number
>y : number
// ok: no reference to this
return y + 1;
>y + 1 : number
>y : number
>1 : 1
}
function f3(z: number): number {
>f3 : (z: number) => number
>z : number
// error: this is implicitly any
return this.a + z;
>this.a + z : any
>this.a : any
>this : any
>a : any
>z : number
}
// error: `this` is `window`, but is still of type `any`
let f4: (b: number) => number = b => this.c + b;
>f4 : (b: number) => number
>b : number
>b => this.c + b : (b: number) => any
>b : number
>this.c + b : any
>this.c : any
>this : typeof globalThis
>c : any
>b : number
let f5 = () => () => this;
>f5 : () => () => typeof globalThis
>() => () => this : () => () => typeof globalThis
>() => this : () => typeof globalThis
>this : typeof globalThis
let f6 = function() { return () => this; };
>f6 : () => () => any
>function() { return () => this; } : () => () => any
>() => this : () => any
>this : any
let f7 = function() { return function() { return this } };
>f7 : () => () => any
>function() { return function() { return this } } : () => () => any
>function() { return this } : () => any
>this : any
|