|
| 1 | +=== tests/cases/conformance/types/thisType/thisTypeInFunctions4.ts === |
| 2 | +type WrongObject = {value: number}; |
| 3 | +>WrongObject : Symbol(WrongObject, Decl(thisTypeInFunctions4.ts, 0, 0)) |
| 4 | +>value : Symbol(value, Decl(thisTypeInFunctions4.ts, 0, 20)) |
| 5 | + |
| 6 | +type CorrectObject = {name: string}; |
| 7 | +>CorrectObject : Symbol(CorrectObject, Decl(thisTypeInFunctions4.ts, 0, 35)) |
| 8 | +>name : Symbol(name, Decl(thisTypeInFunctions4.ts, 1, 22)) |
| 9 | + |
| 10 | +declare function isCorrect(obj: any): obj is CorrectObject |
| 11 | +>isCorrect : Symbol(isCorrect, Decl(thisTypeInFunctions4.ts, 1, 36)) |
| 12 | +>obj : Symbol(obj, Decl(thisTypeInFunctions4.ts, 3, 27)) |
| 13 | +>obj : Symbol(obj, Decl(thisTypeInFunctions4.ts, 3, 27)) |
| 14 | +>CorrectObject : Symbol(CorrectObject, Decl(thisTypeInFunctions4.ts, 0, 35)) |
| 15 | + |
| 16 | +declare function callsCallback(cb: (name: string)=>void) |
| 17 | +>callsCallback : Symbol(callsCallback, Decl(thisTypeInFunctions4.ts, 3, 58)) |
| 18 | +>cb : Symbol(cb, Decl(thisTypeInFunctions4.ts, 5, 31)) |
| 19 | +>name : Symbol(name, Decl(thisTypeInFunctions4.ts, 5, 36)) |
| 20 | + |
| 21 | +function problemFunction(this: CorrectObject | WrongObject): void { |
| 22 | +>problemFunction : Symbol(problemFunction, Decl(thisTypeInFunctions4.ts, 5, 56)) |
| 23 | +>this : Symbol(this, Decl(thisTypeInFunctions4.ts, 7, 25)) |
| 24 | +>CorrectObject : Symbol(CorrectObject, Decl(thisTypeInFunctions4.ts, 0, 35)) |
| 25 | +>WrongObject : Symbol(WrongObject, Decl(thisTypeInFunctions4.ts, 0, 0)) |
| 26 | + |
| 27 | + //check type |
| 28 | + if (!isCorrect(this)) return; |
| 29 | +>isCorrect : Symbol(isCorrect, Decl(thisTypeInFunctions4.ts, 1, 36)) |
| 30 | +>this : Symbol(this, Decl(thisTypeInFunctions4.ts, 7, 25)) |
| 31 | + |
| 32 | + callsCallback((name)=>{ |
| 33 | +>callsCallback : Symbol(callsCallback, Decl(thisTypeInFunctions4.ts, 3, 58)) |
| 34 | +>name : Symbol(name, Decl(thisTypeInFunctions4.ts, 11, 19)) |
| 35 | + |
| 36 | + this.name = name; //should not error |
| 37 | +>this.name : Symbol(name, Decl(thisTypeInFunctions4.ts, 1, 22)) |
| 38 | +>this : Symbol(this, Decl(thisTypeInFunctions4.ts, 7, 25)) |
| 39 | +>name : Symbol(name, Decl(thisTypeInFunctions4.ts, 1, 22)) |
| 40 | +>name : Symbol(name, Decl(thisTypeInFunctions4.ts, 11, 19)) |
| 41 | + |
| 42 | + type T = typeof this; |
| 43 | +>T : Symbol(T, Decl(thisTypeInFunctions4.ts, 12, 25)) |
| 44 | +>this : Symbol(this, Decl(thisTypeInFunctions4.ts, 7, 25)) |
| 45 | + |
| 46 | + }); |
| 47 | +} |
0 commit comments