2014-07-13 01:04:16 +02:00
|
|
|
//// [typeParameterAssignability3.ts]
|
|
|
|
// type parameters are not assignable to one another unless directly or indirectly constrained to one another
|
|
|
|
|
|
|
|
class Foo { foo: string; }
|
|
|
|
|
|
|
|
function foo<T extends Foo, U extends Foo>(t: T, u: U) {
|
|
|
|
var a: T;
|
|
|
|
var b: U;
|
|
|
|
t = a; // ok
|
|
|
|
a = t; // ok
|
|
|
|
|
|
|
|
b = u; // ok
|
|
|
|
u = b; // ok
|
|
|
|
|
|
|
|
t = u; // error
|
|
|
|
u = t; // error
|
|
|
|
}
|
|
|
|
|
|
|
|
class C<T extends Foo, U extends Foo> {
|
|
|
|
t: T;
|
|
|
|
u: U;
|
|
|
|
r = () => {
|
|
|
|
this.t = this.u; // error
|
|
|
|
this.u = this.t; // error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//// [typeParameterAssignability3.js]
|
2014-08-14 15:42:18 +02:00
|
|
|
// type parameters are not assignable to one another unless directly or indirectly constrained to one another
|
2014-07-13 01:04:16 +02:00
|
|
|
var Foo = (function () {
|
|
|
|
function Foo() {
|
|
|
|
}
|
|
|
|
return Foo;
|
|
|
|
})();
|
|
|
|
function foo(t, u) {
|
|
|
|
var a;
|
|
|
|
var b;
|
2014-08-16 00:49:09 +02:00
|
|
|
t = a; // ok
|
|
|
|
a = t; // ok
|
|
|
|
b = u; // ok
|
|
|
|
u = b; // ok
|
|
|
|
t = u; // error
|
|
|
|
u = t; // error
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
var C = (function () {
|
|
|
|
function C() {
|
|
|
|
var _this = this;
|
|
|
|
this.r = function () {
|
2014-08-16 00:49:09 +02:00
|
|
|
_this.t = _this.u; // error
|
|
|
|
_this.u = _this.t; // error
|
2014-07-13 01:04:16 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
return C;
|
|
|
|
})();
|