webdoc-labs / webdoc

Documentation generator for the web
https://www.webdoclabs.com
Other
79 stars 9 forks source link

ReadOnly tags are not respected #67

Closed bigtimebuddy closed 3 years ago

bigtimebuddy commented 3 years ago

JSDoc had a @readonly tag (it also supported the @readOnly variant), this would set a flag on the doc which could be used by the template to display if a property is writable or not. This should probably be a first-class citizen both to support backward compatibility with JSDoc, but also so that we could infer readonly from a few situations such as these:

TypeScript keyword

class MyClass {
  /** Should infer `readonly` status from the TS access. */
  static readonly PROP: number = 20;
}

Using const

/**
 * Also, const objects are readonly, this should also infer.
 */
const MyObj: any = {};

Getter with no Setter

class MyClass {
  /** If no setter, should be readonly as well */
  get name(): string {
    return "";
  }
}
ShukantPal commented 3 years ago

Inference improvements

ShukantPal commented 3 years ago

Implementing the last two cases it bit more complicated so will finish next weekend.

ShukantPal commented 3 years ago

@bigtimebuddy I don't think marking getter-only properties is going to get in since it is too complex. Child classes can easily make it "unreadonly" which would mean the same symbol can both have a readonly behavior and not. I'm not even sure that child classes providing a setter to a parent's getter would properly be merged into one property.