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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
|
//// [derivedUninitializedPropertyDeclaration.ts]
class A {
property = 'x';
m() { return 1 }
}
class B extends A {
property: any; // error
}
class BD extends A {
declare property: any; // ok because it's implicitly initialised
}
class BDBang extends A {
declare property!: any; // ! is not allowed, this is an ambient declaration
}
class BOther extends A {
declare m() { return 2 } // not allowed on methods
declare nonce: any; // ok, even though it's not in the base
declare property = 'y' // initialiser not allowed with declare
}
class U {
declare nonce: any; // ok, even though there's no base
}
class C {
p: string;
}
class D extends C {
p: 'hi'; // error
}
class DD extends C {
declare p: 'bye'; // ok
}
declare class E {
p1: string
p2: string
}
class F extends E {
p1!: 'z'
declare p2: 'alpha'
}
class G extends E {
p1: 'z'
constructor() {
super()
this.p1 = 'z'
}
}
abstract class H extends E {
abstract p1: 'a' | 'b' | 'c'
declare abstract p2: 'a' | 'b' | 'c'
}
interface I {
q: number
}
interface J extends I { }
class J {
r = 5
}
class K extends J {
q!: 1 | 2 | 3 // ok, extends a property from an interface
r!: 4 | 5 // error, from class
}
// #35327
class L {
a: any;
constructor(arg: any) {
this.a = arg;
}
}
class M extends L {
declare a: number;
constructor(arg: number) {
super(arg);
console.log(this.a); // should be OK, M.a is ambient
}
}
//// [derivedUninitializedPropertyDeclaration.js]
"use strict";
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 __());
};
})();
var A = /** @class */ (function () {
function A() {
this.property = 'x';
}
A.prototype.m = function () { return 1; };
return A;
}());
var B = /** @class */ (function (_super) {
__extends(B, _super);
function B() {
return _super !== null && _super.apply(this, arguments) || this;
}
return B;
}(A));
var BD = /** @class */ (function (_super) {
__extends(BD, _super);
function BD() {
return _super !== null && _super.apply(this, arguments) || this;
}
return BD;
}(A));
var BDBang = /** @class */ (function (_super) {
__extends(BDBang, _super);
function BDBang() {
return _super !== null && _super.apply(this, arguments) || this;
}
return BDBang;
}(A));
var BOther = /** @class */ (function (_super) {
__extends(BOther, _super);
function BOther() {
return _super !== null && _super.apply(this, arguments) || this;
}
BOther.prototype.m = function () { return 2; }; // not allowed on methods
return BOther;
}(A));
var U = /** @class */ (function () {
function U() {
}
return U;
}());
var C = /** @class */ (function () {
function C() {
}
return C;
}());
var D = /** @class */ (function (_super) {
__extends(D, _super);
function D() {
return _super !== null && _super.apply(this, arguments) || this;
}
return D;
}(C));
var DD = /** @class */ (function (_super) {
__extends(DD, _super);
function DD() {
return _super !== null && _super.apply(this, arguments) || this;
}
return DD;
}(C));
var F = /** @class */ (function (_super) {
__extends(F, _super);
function F() {
return _super !== null && _super.apply(this, arguments) || this;
}
return F;
}(E));
var G = /** @class */ (function (_super) {
__extends(G, _super);
function G() {
var _this = _super.call(this) || this;
_this.p1 = 'z';
return _this;
}
return G;
}(E));
var H = /** @class */ (function (_super) {
__extends(H, _super);
function H() {
return _super !== null && _super.apply(this, arguments) || this;
}
return H;
}(E));
var J = /** @class */ (function () {
function J() {
this.r = 5;
}
return J;
}());
var K = /** @class */ (function (_super) {
__extends(K, _super);
function K() {
return _super !== null && _super.apply(this, arguments) || this;
}
return K;
}(J));
// #35327
var L = /** @class */ (function () {
function L(arg) {
this.a = arg;
}
return L;
}());
var M = /** @class */ (function (_super) {
__extends(M, _super);
function M(arg) {
var _this = _super.call(this, arg) || this;
console.log(_this.a); // should be OK, M.a is ambient
return _this;
}
return M;
}(L));
|