TS-1068 and TS-1442

307 Views Asked by At

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.

1

There are 1 best solutions below

1
On

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.