2017-07-18 08:39:20 +02:00
|
|
|
//// [tests/cases/conformance/jsdoc/jsdocTypeTagCast.ts] ////
|
|
|
|
|
|
|
|
//// [a.ts]
|
|
|
|
var W: string;
|
|
|
|
|
|
|
|
//// [b.js]
|
|
|
|
// @ts-check
|
|
|
|
var W = /** @type {string} */(/** @type {*} */ (4));
|
|
|
|
|
|
|
|
var W = /** @type {string} */(4); // Error
|
|
|
|
|
|
|
|
/** @type {*} */
|
|
|
|
var a;
|
|
|
|
|
|
|
|
/** @type {string} */
|
|
|
|
var s;
|
|
|
|
|
|
|
|
var a = /** @type {*} */("" + 4);
|
|
|
|
var s = "" + /** @type {*} */(4);
|
|
|
|
|
|
|
|
class SomeBase {
|
|
|
|
constructor() {
|
|
|
|
this.p = 42;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class SomeDerived extends SomeBase {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.x = 42;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class SomeOther {
|
|
|
|
constructor() {
|
|
|
|
this.q = 42;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function SomeFakeClass() {
|
|
|
|
/** @type {string|number} */
|
|
|
|
this.p = "bar";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Type assertion should check for assignability in either direction
|
|
|
|
var someBase = new SomeBase();
|
|
|
|
var someDerived = new SomeDerived();
|
|
|
|
var someOther = new SomeOther();
|
|
|
|
var someFakeClass = new SomeFakeClass();
|
|
|
|
|
|
|
|
someBase = /** @type {SomeBase} */(someDerived);
|
|
|
|
someBase = /** @type {SomeBase} */(someBase);
|
|
|
|
someBase = /** @type {SomeBase} */(someOther); // Error
|
|
|
|
|
|
|
|
someDerived = /** @type {SomeDerived} */(someDerived);
|
|
|
|
someDerived = /** @type {SomeDerived} */(someBase);
|
|
|
|
someDerived = /** @type {SomeDerived} */(someOther); // Error
|
|
|
|
|
|
|
|
someOther = /** @type {SomeOther} */(someDerived); // Error
|
|
|
|
someOther = /** @type {SomeOther} */(someBase); // Error
|
|
|
|
someOther = /** @type {SomeOther} */(someOther);
|
|
|
|
|
|
|
|
someFakeClass = someBase;
|
|
|
|
someFakeClass = someDerived;
|
|
|
|
|
|
|
|
someBase = someFakeClass; // Error
|
|
|
|
someBase = /** @type {SomeBase} */(someFakeClass);
|
|
|
|
|
|
|
|
// Type assertion cannot be a type-predicate type
|
|
|
|
/** @type {number | string} */
|
|
|
|
var numOrStr;
|
|
|
|
/** @type {string} */
|
|
|
|
var str;
|
|
|
|
if(/** @type {numOrStr is string} */(numOrStr === undefined)) { // Error
|
|
|
|
str = numOrStr; // Error, no narrowing occurred
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//// [a.js]
|
|
|
|
var W;
|
|
|
|
//// [b.js]
|
|
|
|
var __extends = (this && this.__extends) || (function () {
|
|
|
|
var extendStatics = Object.setPrototypeOf ||
|
|
|
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
|
|
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
|
|
return function (d, b) {
|
|
|
|
extendStatics(d, b);
|
|
|
|
function __() { this.constructor = d; }
|
|
|
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
// @ts-check
|
|
|
|
var W = ((4));
|
|
|
|
var W = (4); // Error
|
|
|
|
/** @type {*} */
|
|
|
|
var a;
|
|
|
|
/** @type {string} */
|
|
|
|
var s;
|
|
|
|
var a = ("" + 4);
|
2017-08-09 23:27:37 +02:00
|
|
|
var s = "" + /** @type {*} */ (4);
|
2017-08-14 19:11:49 +02:00
|
|
|
var SomeBase = /** @class */ (function () {
|
2017-07-18 08:39:20 +02:00
|
|
|
function SomeBase() {
|
|
|
|
this.p = 42;
|
|
|
|
}
|
|
|
|
return SomeBase;
|
|
|
|
}());
|
2017-08-14 19:11:49 +02:00
|
|
|
var SomeDerived = /** @class */ (function (_super) {
|
2017-07-18 08:39:20 +02:00
|
|
|
__extends(SomeDerived, _super);
|
|
|
|
function SomeDerived() {
|
|
|
|
var _this = _super.call(this) || this;
|
|
|
|
_this.x = 42;
|
|
|
|
return _this;
|
|
|
|
}
|
|
|
|
return SomeDerived;
|
|
|
|
}(SomeBase));
|
2017-08-14 19:11:49 +02:00
|
|
|
var SomeOther = /** @class */ (function () {
|
2017-07-18 08:39:20 +02:00
|
|
|
function SomeOther() {
|
|
|
|
this.q = 42;
|
|
|
|
}
|
|
|
|
return SomeOther;
|
|
|
|
}());
|
|
|
|
function SomeFakeClass() {
|
|
|
|
/** @type {string|number} */
|
|
|
|
this.p = "bar";
|
|
|
|
}
|
|
|
|
// Type assertion should check for assignability in either direction
|
|
|
|
var someBase = new SomeBase();
|
|
|
|
var someDerived = new SomeDerived();
|
|
|
|
var someOther = new SomeOther();
|
|
|
|
var someFakeClass = new SomeFakeClass();
|
2017-08-09 23:27:37 +02:00
|
|
|
someBase = /** @type {SomeBase} */ (someDerived);
|
|
|
|
someBase = /** @type {SomeBase} */ (someBase);
|
|
|
|
someBase = /** @type {SomeBase} */ (someOther); // Error
|
|
|
|
someDerived = /** @type {SomeDerived} */ (someDerived);
|
|
|
|
someDerived = /** @type {SomeDerived} */ (someBase);
|
|
|
|
someDerived = /** @type {SomeDerived} */ (someOther); // Error
|
|
|
|
someOther = /** @type {SomeOther} */ (someDerived); // Error
|
|
|
|
someOther = /** @type {SomeOther} */ (someBase); // Error
|
|
|
|
someOther = /** @type {SomeOther} */ (someOther);
|
2017-07-18 08:39:20 +02:00
|
|
|
someFakeClass = someBase;
|
|
|
|
someFakeClass = someDerived;
|
|
|
|
someBase = someFakeClass; // Error
|
2017-08-09 23:27:37 +02:00
|
|
|
someBase = /** @type {SomeBase} */ (someFakeClass);
|
2017-07-18 08:39:20 +02:00
|
|
|
// Type assertion cannot be a type-predicate type
|
|
|
|
/** @type {number | string} */
|
|
|
|
var numOrStr;
|
|
|
|
/** @type {string} */
|
|
|
|
var str;
|
|
|
|
if ((numOrStr === undefined)) {
|
|
|
|
str = numOrStr; // Error, no narrowing occurred
|
|
|
|
}
|