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
|
//// [targetTypeTest1.ts]
declare class Point
{
constructor(x: number, y: number);
public x: number;
public y: number;
public add(dx: number, dy: number): Point;
static 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) {
this.x = x;
this.y = y;
}
declare function EF1(a:number, b:number):number;
function EF1(a,b) { return a+b; }
var x = EF1(1,2);
// Point.origin declared as type Point
Point.origin = new Point(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) {
return new Point(this.x + dx, this.y + dy);
};
var f : number = 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 = {
x: 0,
y: 0,
add: function(dx, dy) {
return new Point(this.x + dx, this.y + dy);
}
};
declare var z;
z = function(a: number) {
a
}
declare class C {
constructor(a:number, b:number);
public a : number;
public b: number;
C1M1(c:number,d:number):number;
}
function C(a,b) {
this.a=a;
this.b=b;
}
C.prototype =
{ a:0,
b:0,
C1M1: function(c,d) {
return (this.a + c) + (this.b + d);
}
};
//// [targetTypeTest1.js]
// 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) {
this.x = x;
this.y = y;
}
function EF1(a, b) { return a + b; }
var x = EF1(1, 2);
// Point.origin declared as type Point
Point.origin = new Point(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) {
return new Point(this.x + dx, this.y + dy);
};
var f = 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 = {
x: 0,
y: 0,
add: function (dx, dy) {
return new Point(this.x + dx, this.y + dy);
}
};
z = function (a) {
a;
};
function C(a, b) {
this.a = a;
this.b = b;
}
C.prototype =
{ a: 0,
b: 0,
C1M1: function (c, d) {
return (this.a + c) + (this.b + d);
}
};
|