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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
|
=== tests/cases/compiler/targetTypeTest1.ts ===
declare class Point
>Point : Point
{
constructor(x: number, y: number);
>x : number
>y : number
public x: number;
>x : number
public y: number;
>y : number
public add(dx: number, dy: number): Point;
>add : (dx: number, dy: number) => Point
>dx : number
>dy : number
static origin: Point;
>origin : Point
}
// Type provided by extern declaration
// Because Point is a constructor function, this is inferred
// to be Point and return type is inferred to be void
function Point(x, y) {
>Point : typeof Point
>x : any
>y : any
this.x = x;
>this.x = x : any
>this.x : any
>this : any
>x : any
>x : any
this.y = y;
>this.y = y : any
>this.y : any
>this : any
>y : any
>y : any
}
declare function EF1(a:number, b:number):number;
>EF1 : (a: number, b: number) => number
>a : number
>b : number
function EF1(a,b) { return a+b; }
>EF1 : (a: number, b: number) => number
>a : any
>b : any
>a+b : any
>a : any
>b : any
var x = EF1(1,2);
>x : number
>EF1(1,2) : number
>EF1 : (a: number, b: number) => number
>1 : 1
>2 : 2
// Point.origin declared as type Point
Point.origin = new Point(0, 0);
>Point.origin = new Point(0, 0) : Point
>Point.origin : Point
>Point : typeof Point
>origin : Point
>new Point(0, 0) : Point
>Point : typeof Point
>0 : 0
>0 : 0
// Point.prototype declared as type Point
// this inferred as Point because of obj.prop assignment
// dx, dy, and return type inferred using target typing
Point.prototype.add = function(dx, dy) {
>Point.prototype.add = function(dx, dy) { return new Point(this.x + dx, this.y + dy);} : (dx: number, dy: number) => Point
>Point.prototype.add : (dx: number, dy: number) => Point
>Point.prototype : Point
>Point : typeof Point
>prototype : Point
>add : (dx: number, dy: number) => Point
>function(dx, dy) { return new Point(this.x + dx, this.y + dy);} : (dx: number, dy: number) => Point
>dx : number
>dy : number
return new Point(this.x + dx, this.y + dy);
>new Point(this.x + dx, this.y + dy) : Point
>Point : typeof Point
>this.x + dx : any
>this.x : any
>this : any
>x : any
>dx : number
>this.y + dy : any
>this.y : any
>this : any
>y : any
>dy : number
};
var f : number = 5;
>f : number
>5 : 5
// Object literal type inferred using target typing
// this in function add inferred to be type of object literal (i.e. Point)
// dx, dy, and return type of add inferred using target typing
Point.prototype = {
>Point.prototype = { x: 0, y: 0, add: function(dx, dy) { return new Point(this.x + dx, this.y + dy); }} : { x: number; y: number; add: (dx: number, dy: number) => Point; }
>Point.prototype : Point
>Point : typeof Point
>prototype : Point
>{ x: 0, y: 0, add: function(dx, dy) { return new Point(this.x + dx, this.y + dy); }} : { x: number; y: number; add: (dx: number, dy: number) => Point; }
x: 0,
>x : number
>0 : 0
y: 0,
>y : number
>0 : 0
add: function(dx, dy) {
>add : (dx: number, dy: number) => Point
>function(dx, dy) { return new Point(this.x + dx, this.y + dy); } : (dx: number, dy: number) => Point
>dx : number
>dy : number
return new Point(this.x + dx, this.y + dy);
>new Point(this.x + dx, this.y + dy) : Point
>Point : typeof Point
>this.x + dx : any
>this.x : any
>this : any
>x : any
>dx : number
>this.y + dy : any
>this.y : any
>this : any
>y : any
>dy : number
}
};
declare var z;
>z : any
z = function(a: number) {
>z = function(a: number) { a} : (a: number) => void
>z : any
>function(a: number) { a} : (a: number) => void
>a : number
a
>a : number
}
declare class C {
>C : C
constructor(a:number, b:number);
>a : number
>b : number
public a : number;
>a : number
public b: number;
>b : number
C1M1(c:number,d:number):number;
>C1M1 : (c: number, d: number) => number
>c : number
>d : number
}
function C(a,b) {
>C : typeof C
>a : any
>b : any
this.a=a;
>this.a=a : any
>this.a : any
>this : any
>a : any
>a : any
this.b=b;
>this.b=b : any
>this.b : any
>this : any
>b : any
>b : any
}
C.prototype =
>C.prototype = { a:0, b:0, C1M1: function(c,d) { return (this.a + c) + (this.b + d); } } : { a: number; b: number; C1M1: (c: number, d: number) => any; }
>C.prototype : C
>C : typeof C
>prototype : C
{ a:0,
>{ a:0, b:0, C1M1: function(c,d) { return (this.a + c) + (this.b + d); } } : { a: number; b: number; C1M1: (c: number, d: number) => any; }
>a : number
>0 : 0
b:0,
>b : number
>0 : 0
C1M1: function(c,d) {
>C1M1 : (c: number, d: number) => any
>function(c,d) { return (this.a + c) + (this.b + d); } : (c: number, d: number) => any
>c : number
>d : number
return (this.a + c) + (this.b + d);
>(this.a + c) + (this.b + d) : any
>(this.a + c) : any
>this.a + c : any
>this.a : any
>this : any
>a : any
>c : number
>(this.b + d) : any
>this.b + d : any
>this.b : any
>this : any
>b : any
>d : number
}
};
|