2014-07-13 01:04:16 +02:00
|
|
|
//// [derivedClassTransitivity3.ts]
|
|
|
|
// subclassing is not transitive when you can remove required parameters and add optional parameters
|
|
|
|
|
|
|
|
class C<T> {
|
|
|
|
foo(x: T, y: T) { }
|
|
|
|
}
|
|
|
|
|
|
|
|
class D<T> extends C<T> {
|
|
|
|
foo(x: T) { } // ok to drop parameters
|
|
|
|
}
|
|
|
|
|
|
|
|
class E<T> extends D<T> {
|
|
|
|
foo(x: T, y?: number) { } // ok to add optional parameters
|
|
|
|
}
|
|
|
|
|
|
|
|
var c: C<string>;
|
|
|
|
var d: D<string>;
|
|
|
|
var e: E<string>;
|
|
|
|
c = e;
|
|
|
|
var r = c.foo('', '');
|
|
|
|
var r2 = e.foo('', 1);
|
|
|
|
|
|
|
|
//// [derivedClassTransitivity3.js]
|
2014-08-19 19:43:13 +02:00
|
|
|
// subclassing is not transitive when you can remove required parameters and add optional parameters
|
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 C = (function () {
|
|
|
|
function C() {
|
|
|
|
}
|
|
|
|
C.prototype.foo = function (x, y) {
|
|
|
|
};
|
|
|
|
return C;
|
|
|
|
})();
|
|
|
|
var D = (function (_super) {
|
|
|
|
__extends(D, _super);
|
|
|
|
function D() {
|
|
|
|
_super.apply(this, arguments);
|
|
|
|
}
|
|
|
|
D.prototype.foo = function (x) {
|
2014-08-15 22:18:54 +02:00
|
|
|
}; // ok to drop parameters
|
2014-07-13 01:04:16 +02:00
|
|
|
return D;
|
|
|
|
})(C);
|
|
|
|
var E = (function (_super) {
|
|
|
|
__extends(E, _super);
|
|
|
|
function E() {
|
|
|
|
_super.apply(this, arguments);
|
|
|
|
}
|
|
|
|
E.prototype.foo = function (x, y) {
|
2014-08-15 22:18:54 +02:00
|
|
|
}; // ok to add optional parameters
|
2014-07-13 01:04:16 +02:00
|
|
|
return E;
|
|
|
|
})(D);
|
|
|
|
var c;
|
|
|
|
var d;
|
|
|
|
var e;
|
|
|
|
c = e;
|
|
|
|
var r = c.foo('', '');
|
|
|
|
var r2 = e.foo('', 1);
|