dgeni-packages icon indicating copy to clipboard operation
dgeni-packages copied to clipboard

Error parsing the jsdoc type expression "{number| {function(row?:any,index?:number): number}}"

Open dalelotts opened this issue 8 years ago • 7 comments

I'm trying to document a property that returns a number or a function - this seems to work with pure jsdocs but not here

* @type {number|function(row?:any,index?:number): number}

The property is defined as follows. @Input() rowHeight: (number | ((row?: any, index?: number) => number)) = 0;

If I removing the ?'s it works, but I believe they will no longer appear as optional parameters.

Any suggestions on how we can work around this?

dalelotts avatar May 18 '17 16:05 dalelotts

@dalelotts - can you give me a bit more information. Is it the @type tag that is not working? What is being output?

petebacondarwin avatar May 19 '17 07:05 petebacondarwin

The library we use to parse the types is https://github.com/hegemonic/catharsis Perhaps this doesn't support this notation?

petebacondarwin avatar May 19 '17 07:05 petebacondarwin

Call stack here:

Error: Error parsing the jsdoc type expression "{number|function(row?:any,index?:number): number}"
    at /Users/dale.lotts/dev/vdl-angular/node_modules/dgeni-packages/jsdoc/services/transforms/extract-type.js:56:15
    at /Users/dale.lotts/dev/vdl-angular/node_modules/dgeni-packages/jsdoc/processors/extract-tags.js:166:19
    at arrayEach (/Users/dale.lotts/dev/vdl-angular/node_modules/lodash/lodash.js:537:11)
    at Function.forEach (/Users/dale.lotts/dev/vdl-angular/node_modules/lodash/lodash.js:9359:14)
    at /Users/dale.lotts/dev/vdl-angular/node_modules/dgeni-packages/jsdoc/processors/extract-tags.js:165:11
    at Object.tagDef.getProperty (/Users/dale.lotts/dev/vdl-angular/node_modules/dgeni-packages/jsdoc/processors/extract-tags.js:54:17)
    at readTags (/Users/dale.lotts/dev/vdl-angular/node_modules/dgeni-packages/jsdoc/processors/extract-tags.js:138:22)
    at /Users/dale.lotts/dev/vdl-angular/node_modules/dgeni-packages/jsdoc/processors/extract-tags.js:86:11
    at arrayEach (/Users/dale.lotts/dev/vdl-angular/node_modules/lodash/lodash.js:537:11)
    at Function.forEach (/Users/dale.lotts/dev/vdl-angular/node_modules/lodash/lodash.js:9359:14)
    at tagExtractor (/Users/dale.lotts/dev/vdl-angular/node_modules/dgeni-packages/jsdoc/processors/extract-tags.js:65:9)

dalelotts avatar May 19 '17 18:05 dalelotts

OK, I'll take a look...

petebacondarwin avatar May 20 '17 10:05 petebacondarwin

Right! I can reproduce this in a unit test. It look like catharsis does not like this syntax...

petebacondarwin avatar May 20 '17 10:05 petebacondarwin

@dalelotts - it seems that you are using an invalid syntax. The correct syntax should not include the parameter names. For example the following test passes in dgeni-packages:

  it('should handle optional function params', function() {
    value = '{number|function(?any,?number): number} some description';
    value = transform(doc, tag, value);
    expect(tag.typeList).toEqual([ 'number', 'function(?any, ?number): number' ]);
  });

petebacondarwin avatar May 20 '17 11:05 petebacondarwin

See https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#optional-argument-in-a-function-type for more information.

petebacondarwin avatar May 20 '17 11:05 petebacondarwin