c184184713
* Add helpers that understand constructor functions * getEffectiveConstructSignatures gets construct signatures from type, and call signatures from constructor functions if there are no construct signatures. * getEffectiveConstructSignatureReturnType gets the "JS Class type" for constructor functions, and the return type of signatures for all other declarations. This is a first step toward making constructor functions have construct signatures instead of call signatures, which will also contribute to fixing instantiation of generic constructor functions, which is basically broken right now. Note that the baselines *improve* but, because of the previously mentioned generic problem, are still not correct. Construct signatures for constructor functions and generic constructor functions turns out to be an intertwined problem. * Correct correct originalBaseType And, for now, return anyType for generic constructor functions used as base types. Don't give an incorrect error based on the function's return type, which is usually void. * Add error examples to tests * Add construct signatures instead of getEffective* functions * Fix typo in baseline * Remove pesky newline I thought I got rid of it! * Test of constructor tag on object literal method It doesn't work, and shouldn't in the future, because it's a runtime error.
60 lines
1 KiB
TypeScript
60 lines
1 KiB
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(); // error: @class tag requires 'new'
|
|
const c3_v2 = new C3();
|
|
|
|
/** @class */
|
|
var C4 = function () {
|
|
if (!(this instanceof C4)) return new C4();
|
|
};
|
|
|
|
const c4_v1 = C4(); // error: @class tag requires 'new'
|
|
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();
|
|
|
|
|
|
/**
|
|
* @constructor
|
|
* @param {number} num
|
|
*/
|
|
function C7(num) {}
|
|
|
|
var c7_v1 = new C7();
|