jumpinjackie / jsdoc-typescript-plugin

Experimental JSDoc plugin to generate TypeScript definition files (.d.ts) from JSDoc-annotated source
34 stars 7 forks source link

Base methods of Cesium class is not defined #76

Closed bariscicek closed 7 years ago

bariscicek commented 7 years ago

I try to generate Cesium typings. It works well for the classes of Cesium, however top methods on Cesium class are not defined in cesium.d.ts.

Some examples are: barycentrisCoordinates, createCommand, clone etc.

Normally these methods are called like Cesium.barycentricCoordinates(), though as they are not included in definitions, transpiler warn about them.

I tried various config items with no luck.

jumpinjackie commented 7 years ago

Thanks for the report.

While this plugin will generate a syntactically valid cesium.d.ts, there are still many corner cases that makes the typings itself un-usable at the moment.

Firstly, do you know if these missing methods are covered in Cesium's API documentation?

bariscicek commented 7 years ago

Yes they are, indeed during d.ts generation when I debug docklet.longname I see module:barycentricCorrdinates for example. But they are not included in .d.ts. Not sure where else to debug further in the code.

jumpinjackie commented 7 years ago

Ah, JSDoc is lying to me.

Apparently if a doclet takes parameters like a function, returns values like a function, it's kind can still be something other than function! Yet another corner case to handle.

bariscicek commented 7 years ago

Anything that I can give a hand to fix it? Another issue is regarding constants.

For example Cesium.Color.RED, Cesium.Color.WHITE somehow not included in cesium.d.ts though it might be related.

jumpinjackie commented 7 years ago

I'm at a hackathon this weekend, so if you want a stab at this.

Basically, an instance of jsdoc.IDoclet can have parameters params and/or return values returns, but the its kind can give values other than class or function

In the case of barycentricCoordinates. It's a function, but its kind returns module (???)

So we need a utility method that fetches the true kind from an jsdoc.IDoclet like this:

class DocletKind {
...
    public static getDocletKind(doclet: jsdoc.IDoclet): string {
        //Not a function or constructor eh?
        if (doclet.kind != DocletKind.Function && doclet.kind != DocletKind.Class) {
            if (doclet.params && doclet.params.length > 0) {
                return DocletKind.Function; //LIAR
            }
            if (doclet.returns && doclet.returns.length > 0) {
                return DocletKind.Function; //LIAR
            }
        }
        return doclet.kind;
    }
}

And then replace all doclet kind testing/checking with calls to this function instead.

As to constants, I suspect that we may need to apply an export keyword to an var declarations we emit.

lRawd commented 7 years ago

Methods like Cesium.createTileMapServiceImageryProvider, which are now generated, have Object as the parameter type. IXXXOptions are not generated for these new methods parameters since null is always passed as the context into TSMethod.studyParameters.