englercj / tsd-jsdoc

Compiles JSDoc annotated JavaScript into a Typescript Definition file (.d.ts)
MIT License
315 stars 42 forks source link

How to generate with a ES5 JS file that is dependent on another library? #141

Open yaustar opened 4 years ago

yaustar commented 4 years ago

I'm trying to generate ts definitions for the following library: https://github.com/playcanvas/playcanvas-tween

It is dependent on the PlayCanvas engine as it adds new functionality: https://github.com/playcanvas/engine

So far, I've tried the following:

/**
 * @external "pc"
 */

/**
 * @external "pc.Application"
 */

/**
 * @external "pc.Entity"
 */

pc.extend(pc, function () {

    /**
     * @name pc.TweenManager
     * @description Handles updating tweens
     * @param {pc.Application} app  The application
     */
    var TweenManager = function (app) {
        this._app = app;
        this._tweens = [];
        this._add = []; // to be added
    };

And the following config:

{
    "source": {
        "include": ["tween.js"]
    },
    "opts": {
        "destination": "build",
        "outFile": "playcanvas-tween.d.ts",
        "recurse": true,
        "template": "node_modules/tsd-jsdoc/dist"
    }
}

And get the following error:

[TSD-JSDoc] tween.js:15:4 Failed to find parent of doclet 'pc.TweenManager' using memberof 'pc', this is likely due to invalid JSDoc.
[TSD-JSDoc] tween.js:52:4 Failed to find parent of doclet 'pc.Tween' using memberof 'pc', this is likely due to invalid JSDoc.
[TSD-JSDoc] tween.js:681:4 Failed to find parent of doclet 'pc.Application#tween' using memberof 'pc.Application', this is likely due to invalid JSDoc.
[TSD-JSDoc] tween.js:699:4 Failed to find parent of doclet 'pc.Entity#tween' using memberof 'pc.Entity', this is likely due to invalid JSDoc.
/Users/stevenyau/Dev/playcanvas-tween/node_modules/tsd-jsdoc/dist/assert_never.js:5
    throw new Error("Unexpected object: " + JSON.stringify(x));

Error: Unexpected object: {"comment":"/**\n * @external \"pc\"\n */","meta":{"filename":"tween.js","lineno":1,"columnno":0,"path":"/Users/stevenyau/Dev/playcanvas-tween","code":{}},"kind":"external","name":"\"pc\"","longname":"external:\"pc\"","scope":"global","___id":"T000002R028308","___s":true}
    at Object.assertNever (/Users/stevenyau/Dev/playcanvas-tween/node_modules/tsd-jsdoc/dist/assert_never.js:5:11)
    at Emitter._parseTreeNode (/Users/stevenyau/Dev/playcanvas-tween/node_modules/tsd-jsdoc/dist/Emitter.js:196:39)

I understand that the @external tag is not supported, what would be the best way to approach this?