2014-07-13 01:04:16 +02:00
|
|
|
//// [covariance1.ts]
|
|
|
|
module M {
|
|
|
|
|
|
|
|
interface X { m1:number; }
|
|
|
|
export class XX implements X { constructor(public m1:number) { } }
|
|
|
|
|
|
|
|
interface Y { x:X; }
|
|
|
|
|
|
|
|
export function f(y:Y) { }
|
|
|
|
|
|
|
|
var a:X;
|
|
|
|
f({x:a}); // ok
|
|
|
|
|
|
|
|
var b:XX;
|
|
|
|
f({x:b}); // ok covariant subtype
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//// [covariance1.js]
|
|
|
|
var M;
|
|
|
|
(function (M) {
|
|
|
|
var XX = (function () {
|
|
|
|
function XX(m1) {
|
|
|
|
this.m1 = m1;
|
|
|
|
}
|
|
|
|
return XX;
|
|
|
|
})();
|
|
|
|
M.XX = XX;
|
2015-02-07 03:45:09 +01:00
|
|
|
function f(y) { }
|
2014-07-13 01:04:16 +02:00
|
|
|
M.f = f;
|
|
|
|
var a;
|
2014-08-16 00:49:09 +02:00
|
|
|
f({ x: a }); // ok
|
2014-07-13 01:04:16 +02:00
|
|
|
var b;
|
2014-08-16 00:49:09 +02:00
|
|
|
f({ x: b }); // ok covariant subtype
|
2014-07-13 01:04:16 +02:00
|
|
|
})(M || (M = {}));
|