2014-07-13 01:04:16 +02:00
|
|
|
//// [propertyAccessOnTypeParameterWithConstraints2.ts]
|
|
|
|
// generic types should behave as if they have properties of their constraint type
|
|
|
|
|
|
|
|
class A {
|
|
|
|
foo(): string { return ''; }
|
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A {
|
|
|
|
bar(): string {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class C<U extends A, T extends A> {
|
|
|
|
f() {
|
|
|
|
var x: U;
|
|
|
|
var a = x['foo'](); // should be string
|
|
|
|
return a + x.foo();
|
|
|
|
}
|
|
|
|
|
|
|
|
g(x: U) {
|
|
|
|
var a = x['foo'](); // should be string
|
|
|
|
return a + x.foo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//class C<U extends T, T extends A> {
|
|
|
|
// f() {
|
|
|
|
// var x: U;
|
|
|
|
// var a = x['foo'](); // should be string
|
|
|
|
// return a + x.foo();
|
|
|
|
// }
|
|
|
|
|
|
|
|
// g(x: U) {
|
|
|
|
// var a = x['foo'](); // should be string
|
|
|
|
// return a + x.foo();
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
var r1 = (new C<B, A>()).f();
|
|
|
|
var r1b = (new C<B, A>()).g(new B());
|
|
|
|
|
|
|
|
interface I<U extends A, T extends A> {
|
|
|
|
foo: U;
|
|
|
|
}
|
|
|
|
//interface I<U extends T, T extends A> {
|
|
|
|
// foo: U;
|
|
|
|
//}
|
|
|
|
var i: I<B, A>;
|
|
|
|
var r2 = i.foo.foo();
|
|
|
|
var r2b = i.foo['foo']();
|
|
|
|
|
|
|
|
var a: {
|
|
|
|
<U extends A, T extends A>(): U;
|
|
|
|
<U extends A, T extends A>(x: U): U;
|
|
|
|
<U extends A, T extends A>(x: U, y: T): U;
|
|
|
|
}
|
|
|
|
//var a: {
|
|
|
|
// <U extends T, T extends A>(): U;
|
|
|
|
// <U extends T, T extends A>(x: U): U;
|
|
|
|
// <U extends T, T extends A>(x: U, y: T): U;
|
|
|
|
//}
|
|
|
|
var r3 = a<A, A>().foo();
|
|
|
|
var r3b = a()['foo']();
|
|
|
|
// parameter supplied for type argument inference to succeed
|
|
|
|
var aB = new B();
|
|
|
|
var r3c = a(aB, aB).foo();
|
|
|
|
var r3d = a(aB, aB)['foo']();
|
|
|
|
|
|
|
|
var b = {
|
|
|
|
foo: <U extends A, T extends A>(x: U, y: T) => {
|
|
|
|
var a = x['foo'](); // should be string
|
|
|
|
return a + x.foo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//var b = {
|
|
|
|
// foo: <U extends T, T extends A>(x: U, y: T) => {
|
|
|
|
// var a = x['foo'](); // should be string
|
|
|
|
// return a + x.foo();
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
var r4 = b.foo(aB, aB); // no inferences for T so constraint isn't satisfied, error
|
|
|
|
|
|
|
|
//// [propertyAccessOnTypeParameterWithConstraints2.js]
|
2014-08-19 19:43:13 +02:00
|
|
|
// generic types should behave as if they have properties of their constraint type
|
2014-07-13 01:04:16 +02:00
|
|
|
var __extends = this.__extends || function (d, b) {
|
|
|
|
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
|
|
function __() { this.constructor = d; }
|
|
|
|
__.prototype = b.prototype;
|
|
|
|
d.prototype = new __();
|
|
|
|
};
|
|
|
|
var A = (function () {
|
|
|
|
function A() {
|
|
|
|
}
|
|
|
|
A.prototype.foo = function () {
|
|
|
|
return '';
|
|
|
|
};
|
|
|
|
return A;
|
|
|
|
})();
|
|
|
|
var B = (function (_super) {
|
|
|
|
__extends(B, _super);
|
|
|
|
function B() {
|
|
|
|
_super.apply(this, arguments);
|
|
|
|
}
|
|
|
|
B.prototype.bar = function () {
|
|
|
|
return '';
|
|
|
|
};
|
|
|
|
return B;
|
|
|
|
})(A);
|
|
|
|
var C = (function () {
|
|
|
|
function C() {
|
|
|
|
}
|
|
|
|
C.prototype.f = function () {
|
|
|
|
var x;
|
2014-08-15 22:18:54 +02:00
|
|
|
var a = x['foo'](); // should be string
|
2014-07-13 01:04:16 +02:00
|
|
|
return a + x.foo();
|
|
|
|
};
|
|
|
|
C.prototype.g = function (x) {
|
2014-08-15 22:18:54 +02:00
|
|
|
var a = x['foo'](); // should be string
|
2014-07-13 01:04:16 +02:00
|
|
|
return a + x.foo();
|
|
|
|
};
|
|
|
|
return C;
|
|
|
|
})();
|
2014-08-12 00:54:12 +02:00
|
|
|
//class C<U extends T, T extends A> {
|
|
|
|
// f() {
|
|
|
|
// var x: U;
|
|
|
|
// var a = x['foo'](); // should be string
|
|
|
|
// return a + x.foo();
|
|
|
|
// }
|
|
|
|
// g(x: U) {
|
|
|
|
// var a = x['foo'](); // should be string
|
|
|
|
// return a + x.foo();
|
|
|
|
// }
|
|
|
|
//}
|
2014-07-13 01:04:16 +02:00
|
|
|
var r1 = (new C()).f();
|
|
|
|
var r1b = (new C()).g(new B());
|
2014-08-12 00:54:12 +02:00
|
|
|
//interface I<U extends T, T extends A> {
|
|
|
|
// foo: U;
|
|
|
|
//}
|
2014-07-13 01:04:16 +02:00
|
|
|
var i;
|
|
|
|
var r2 = i.foo.foo();
|
|
|
|
var r2b = i.foo['foo']();
|
|
|
|
var a;
|
2014-08-12 00:54:12 +02:00
|
|
|
//var a: {
|
|
|
|
// <U extends T, T extends A>(): U;
|
|
|
|
// <U extends T, T extends A>(x: U): U;
|
|
|
|
// <U extends T, T extends A>(x: U, y: T): U;
|
|
|
|
//}
|
2014-07-13 01:04:16 +02:00
|
|
|
var r3 = a().foo();
|
|
|
|
var r3b = a()['foo']();
|
2014-08-12 00:54:12 +02:00
|
|
|
// parameter supplied for type argument inference to succeed
|
2014-07-13 01:04:16 +02:00
|
|
|
var aB = new B();
|
|
|
|
var r3c = a(aB, aB).foo();
|
|
|
|
var r3d = a(aB, aB)['foo']();
|
|
|
|
var b = {
|
|
|
|
foo: function (x, y) {
|
2014-08-15 22:18:54 +02:00
|
|
|
var a = x['foo'](); // should be string
|
2014-07-13 01:04:16 +02:00
|
|
|
return a + x.foo();
|
|
|
|
}
|
|
|
|
};
|
2014-08-12 00:54:12 +02:00
|
|
|
//var b = {
|
|
|
|
// foo: <U extends T, T extends A>(x: U, y: T) => {
|
|
|
|
// var a = x['foo'](); // should be string
|
|
|
|
// return a + x.foo();
|
|
|
|
// }
|
|
|
|
//}
|
2014-08-15 23:32:08 +02:00
|
|
|
var r4 = b.foo(aB, aB); // no inferences for T so constraint isn't satisfied, error
|