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
|
//// [narrowingOfDottedNames.ts]
// Repro from #8383
class A {
prop!: { a: string; };
}
class B {
prop!: { b: string; }
}
function isA(x: any): x is A {
return x instanceof A;
}
function isB(x: any): x is B {
return x instanceof B;
}
function f1(x: A | B) {
while (true) {
if (x instanceof A) {
x.prop.a;
}
else if (x instanceof B) {
x.prop.b;
}
}
}
function f2(x: A | B) {
while (true) {
if (isA(x)) {
x.prop.a;
}
else if (isB(x)) {
x.prop.b;
}
}
}
// Repro from #28100
class Foo1
{
x: number; // Error
constructor() {
if (this instanceof Boolean) {
}
}
}
class Foo2
{
x: number; // Error
constructor() {
}
}
// Repro from #29513
class AInfo {
a_count: number = 1;
}
class BInfo {
b_count: number = 1;
}
class Base {
id: number = 0;
}
class A2 extends Base {
info!: AInfo;
}
class B2 extends Base {
info!: BInfo;
}
let target: Base = null as any;
while (target) {
if (target instanceof A2) {
target.info.a_count = 3;
}
else if (target instanceof B2) {
const j: BInfo = target.info;
}
}
//// [narrowingOfDottedNames.js]
"use strict";
// Repro from #8383
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() {
}
return A;
}());
var B = /** @class */ (function () {
function B() {
}
return B;
}());
function isA(x) {
return x instanceof A;
}
function isB(x) {
return x instanceof B;
}
function f1(x) {
while (true) {
if (x instanceof A) {
x.prop.a;
}
else if (x instanceof B) {
x.prop.b;
}
}
}
function f2(x) {
while (true) {
if (isA(x)) {
x.prop.a;
}
else if (isB(x)) {
x.prop.b;
}
}
}
// Repro from #28100
var Foo1 = /** @class */ (function () {
function Foo1() {
if (this instanceof Boolean) {
}
}
return Foo1;
}());
var Foo2 = /** @class */ (function () {
function Foo2() {
}
return Foo2;
}());
// Repro from #29513
var AInfo = /** @class */ (function () {
function AInfo() {
this.a_count = 1;
}
return AInfo;
}());
var BInfo = /** @class */ (function () {
function BInfo() {
this.b_count = 1;
}
return BInfo;
}());
var Base = /** @class */ (function () {
function Base() {
this.id = 0;
}
return Base;
}());
var A2 = /** @class */ (function (_super) {
__extends(A2, _super);
function A2() {
return _super !== null && _super.apply(this, arguments) || this;
}
return A2;
}(Base));
var B2 = /** @class */ (function (_super) {
__extends(B2, _super);
function B2() {
return _super !== null && _super.apply(this, arguments) || this;
}
return B2;
}(Base));
var target = null;
while (target) {
if (target instanceof A2) {
target.info.a_count = 3;
}
else if (target instanceof B2) {
var j = target.info;
}
}
|