1

I have a codebase that I'm looking to slowly migrate to 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.

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:

$ 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?

1 Answer 1

2

This seems to work:

/** @type {typeof Base} */
Thing.super_;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.