简体   繁体   English

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

[英]How to document a JS class in Typescript with JSDoc

I have a codebase that I'm looking to slowly migrate to Typescript. 我有一个代码库,希望能慢慢迁移到Typescript。 This means I create classes the non-ES6 way using util.inherits from Node, and would like to use JSDoc type annotations rather than converting to Typescript at this time. 这意味着我将使用Node的util.inherits以非ES6的方式创建类,并且希望使用JSDoc类型注释,而不是此时转换为Typescript。

But I'm having a problem typing classes: 但是我在输入类时遇到问题:

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");

When running Typescript gives the following output: 运行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);
                 ~~~~~~

Is there a way to document the super_ property created by inherits using JSDoc? 有没有办法记录使用JSDoc inherits创建的super_属性?

This seems to work: 这似乎可行:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM