File: thisTypeInFunctions4.types

package info (click to toggle)
node-typescript 5.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 497,488 kB
  • sloc: javascript: 2,107,274; makefile: 6; sh: 1
file content (50 lines) | stat: -rw-r--r-- 1,514 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//// [tests/cases/conformance/types/thisType/thisTypeInFunctions4.ts] ////

=== thisTypeInFunctions4.ts ===
type WrongObject = {value: number};
>WrongObject : { value: number; }
>value : number

type CorrectObject = {name: string};
>CorrectObject : { name: string; }
>name : string

declare function isCorrect(obj: any): obj is CorrectObject
>isCorrect : (obj: any) => obj is CorrectObject
>obj : any

declare function callsCallback(cb: (name: string)=>void)
>callsCallback : (cb: (name: string) => void) => any
>cb : (name: string) => void
>name : string

function problemFunction(this: CorrectObject | WrongObject): void {
>problemFunction : (this: CorrectObject | WrongObject) => void
>this : WrongObject | CorrectObject

    //check type
    if (!isCorrect(this)) return;
>!isCorrect(this) : boolean
>isCorrect(this) : boolean
>isCorrect : (obj: any) => obj is CorrectObject
>this : WrongObject | CorrectObject

    callsCallback((name)=>{
>callsCallback((name)=>{        this.name = name; //should not error        type T = typeof this;    }) : any
>callsCallback : (cb: (name: string) => void) => any
>(name)=>{        this.name = name; //should not error        type T = typeof this;    } : (name: string) => void
>name : string

        this.name = name; //should not error
>this.name = name : string
>this.name : string
>this : CorrectObject
>name : string
>name : string

        type T = typeof this;
>T : CorrectObject
>this : CorrectObject

    });
}