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 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
//// [classExtendingClassLikeType.ts]
interface Base<T, U> {
x: T;
y: U;
}
// Error, no Base constructor function
class D0 extends Base<string, string> {
}
interface BaseConstructor {
new (x: string, y: string): Base<string, string>;
new <T>(x: T): Base<T, T>;
new <T>(x: T, y: T): Base<T, T>;
new <T, U>(x: T, y: U): Base<T, U>;
}
declare function getBase(): BaseConstructor;
class D1 extends getBase() {
constructor() {
super("abc", "def");
this.x = "x";
this.y = "y";
}
}
class D2 extends getBase() <number> {
constructor() {
super(10);
super(10, 20);
this.x = 1;
this.y = 2;
}
}
class D3 extends getBase() <string, number> {
constructor() {
super("abc", 42);
this.x = "x";
this.y = 2;
}
}
// Error, no constructors with three type arguments
class D4 extends getBase() <string, string, string> {
}
interface BadBaseConstructor {
new (x: string): Base<string, string>;
new (x: number): Base<number, number>;
}
declare function getBadBase(): BadBaseConstructor;
// Error, constructor return types differ
class D5 extends getBadBase() {
}
//// [classExtendingClassLikeType.js]
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// Error, no Base constructor function
var D0 = /** @class */ (function (_super) {
__extends(D0, _super);
function D0() {
return _super !== null && _super.apply(this, arguments) || this;
}
return D0;
}(Base));
var D1 = /** @class */ (function (_super) {
__extends(D1, _super);
function D1() {
var _this = _super.call(this, "abc", "def") || this;
_this.x = "x";
_this.y = "y";
return _this;
}
return D1;
}(getBase()));
var D2 = /** @class */ (function (_super) {
__extends(D2, _super);
function D2() {
var _this = _super.call(this, 10) || this;
_this = _super.call(this, 10, 20) || this;
_this.x = 1;
_this.y = 2;
return _this;
}
return D2;
}(getBase()));
var D3 = /** @class */ (function (_super) {
__extends(D3, _super);
function D3() {
var _this = _super.call(this, "abc", 42) || this;
_this.x = "x";
_this.y = 2;
return _this;
}
return D3;
}(getBase()));
// Error, no constructors with three type arguments
var D4 = /** @class */ (function (_super) {
__extends(D4, _super);
function D4() {
return _super !== null && _super.apply(this, arguments) || this;
}
return D4;
}(getBase()));
// Error, constructor return types differ
var D5 = /** @class */ (function (_super) {
__extends(D5, _super);
function D5() {
return _super !== null && _super.apply(this, arguments) || this;
}
return D5;
}(getBadBase()));
|