如何使用JSDoc在Typescript中记录JS类

时间:2018-08-28 15:23:35

标签: javascript typescript jsdoc

我有一个代码库,希望能慢慢迁移到Typescript。这意味着我使用Node的util.inherits以非ES6的方式创建类,并且希望使用JSDoc类型注释,而不是此时转换为Typescript。

但是我在输入类时遇到问题:

var util = require("util");

function Base() {
}

/**
 * @constructor
 * @param {string} arg
 */
function Thing(arg) {
    Thing.super_.call(this);

    this.x = arg;
}

util.inherits(Thing, Base);

var thing = new Thing("test");

运行Typescript时,输出如下:

$ tsc --noEmit --allowJs --checkJs .\test.js
test.js:11:15 - error TS2339: Property 'super_' does not exist on type 'typeof Thing'.

11         Thing.super_.call(this);
                 ~~~~~~

是否可以记录由super_使用JSDoc创建的inherits属性?

1 个答案:

答案 0 :(得分:1)

这似乎可行:

/** @type {typeof Base} */
Thing.super_;