我有一个代码库,希望能慢慢迁移到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);
~~~~~~
有没有办法记录由JSDoc使用
super_
创建的inherits
属性? 最佳答案
这似乎可行:
/** @type {typeof Base} */
Thing.super_;
关于javascript - 如何使用JSDoc在Typescript中记录JS类,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52061421/