* Properly infer `this` in tagged `@constructor`s. `c.prototype.method = function() { this }` was already supported. This commit add support to two more kinds relying on the JSDoc `@constructor` tag. These are: 1. `/** @constructor */ function Example() { this }` 2. `/** @constructor */ var Example = function() { this }` * Update the baseline for js constructorFunctions. C3 and C4 `this` was set as `any`, now it is properly showing as the class type. * Fix lint errors * Add circular initialisers to constructo fn tests. * Error (`TS2348`) if calling tagged js constructors When calling a JS function explicitly tagged with either `@class` or `@constructor` the checker should throw a TS2348 not callable error. * Don't resolve jsdoc classes with construct sigs. This undoes the last commit that sought to change how js functions tagged with `@class` were inferred. For some reason, currently unknown, giving those functions construct signatures causes issues in property assignment/member resolution (as seen in the `typeFromPropertyAssignment12` test case). Instead of changing the signature resolution, the error is explicitly generated in `resolveCallExpression` for those functions.
52 lines
856 B
TypeScript
52 lines
856 B
TypeScript
// @allowJs: true
|
|
// @checkJs: true
|
|
// @noEmit: true
|
|
// @filename: index.js
|
|
|
|
function C1() {
|
|
if (!(this instanceof C1)) return new C1();
|
|
this.x = 1;
|
|
}
|
|
|
|
const c1_v1 = C1();
|
|
const c1_v2 = new C1();
|
|
|
|
var C2 = function () {
|
|
if (!(this instanceof C2)) return new C2();
|
|
this.x = 1;
|
|
};
|
|
|
|
const c2_v1 = C2();
|
|
const c2_v2 = new C2();
|
|
|
|
/** @class */
|
|
function C3() {
|
|
if (!(this instanceof C3)) return new C3();
|
|
};
|
|
|
|
const c3_v1 = C3();
|
|
const c3_v2 = new C3();
|
|
|
|
/** @class */
|
|
var C4 = function () {
|
|
if (!(this instanceof C4)) return new C4();
|
|
};
|
|
|
|
const c4_v1 = C4();
|
|
const c4_v2 = new C4();
|
|
|
|
var c5_v1;
|
|
c5_v1 = function f() { };
|
|
new c5_v1();
|
|
|
|
var c5_v2;
|
|
c5_v2 = class { };
|
|
new c5_v2();
|
|
|
|
/** @class */
|
|
function C6() {
|
|
this.functions = [x => x, x => x + 1, x => x - 1]
|
|
};
|
|
|
|
var c6_v1 = new C6();
|