1

I have a class which has a member public offerTags: [ 'Array' ].<ITag>; The above line is throwing error Unexpected token. A constructor, method, accessor, or property was expected.ts(1068) and Expected '=' for property initializer.ts(1442) . This code is auto-generated from protobufjs models. The editor is not able to understand the above format. Is there a specific TS setting or version that I should make so that I don't get the above error?

interface ITag {      
  /** Tag namespace */ 
  namespace?: (string|null);      

  /** Tag name */
  name?: (string|null); 
} 
class Offer {      
  /** Offer id. */     
  public id?: string;      

  /** Offer name. */     
  public name?: string;       
 
  /** Offer offerTags. */     
  public offerTags: [ 'Array' ].<ITag>;      

  /** Offer validityInterval. */     
  public validityInterval?: (IAbsoluteTimeInterval|null); 
}

In the above class definition for Offer, public offerTags: [ 'Array' ].<ITag>; is throwing error Expected '=' for property initializer.ts(1442) and Unexpected token. A constructor, method, accessor, or property was expected.ts(1068).

To me the syntax for offerTags attribute looks odd, ideally an array would be declared as public offerTags: ITag[] . Because of the above issue I'm not able to access the attributes declared after offerTags attribute such as validityInrerval.

cutiecatie
  • 61
  • 6

1 Answers1

1

This seems to be a bug in protobufjs and someone else reported the same issue here: generated .d.ts syntax error #1306

Based on the thread, it seems related to JSDoc < 3.6.1. Current protobfjs version (6.10.2) depends on JSDoc 3.6.3, so I guess it should be working fine with that latest version.

For further analysis, you would have to publish a small reproducible sample.

Ben
  • 1,331
  • 2
  • 8
  • 15
  • There is another bug with v6.10.2 in which not all interfaces are generated from the protobuf models because of jsdoc version >3.6. https://github.com/protobufjs/protobuf.js/issues/1222 . So it seems any version of protobufjs is having an issue with generated TS. – cutiecatie Mar 22 '22 at 18:51