question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RFC: Detecting whether a dependency implements TSDoc

See original GitHub issue

Consider this example from API Extractor:

/** @beta */
export interface IPrepareOptions {
  target: string;
}

/** @public */
export interface IWidget {
  /** Renders the widget */
  render(): void;
}

/** @public */
export class Widget implements IWidget {
  /** {@inheritdoc IWidget.render} */  // <-- inherited doc comment
  render(): void;

  prepare(options: IPrepareOptions): void;  // <-- inconsistent visibility error
}

This illustrates a couple kinds of cross references:

  1. Documentation inheritance: The Widget.render docs are copied from IWidget.render using the {@inheritdoc} tag. This avoids having to write duplicate documentation.
  2. Visibility checking: API Extractor allows API items to be marked with a “release tag” such as @beta. For a public release, only the @public definitions will be included in the generated *.d.ts rollup file; the other definitions are trimmed out. In the above example, the analyzer must report an error because if IPrepareOptions gets trimmed, then Widget.prepare won’t be able to consumer that interface.

Now, suppose that IWidget and IPrepareOptions are imported from a separate NPM package called widget-lib. This is no problem – API Extractor can simply parse the TSDoc comments from this file:

./node_modules/widget-lib/lib/index.d.ts

This seems fine on the surface, but the node_modules folder is full of *.d.ts files that have no awareness of API Extractor. Their doc comments might randomly contain a string such as @beta, or they might simply have malformed comments that would normally be reported as a TSDoc error.

We need a way to determine whether a given NPM package actually implements TSDoc or not.

Our proposal is to add a custom field tsdoc to the package.json file format like this:

{
  "name": "widget-lib",
  "version": "1.0.0",
  "main": "lib/index.d.ts",
  "typings": "lib/index.js",
  "tsdoc": {
    "tsdocFlavor": "AEDoc"
  }
}

(Note that the CommonJS spec specifically allows for custom fields.)

Initially, the tsdoc block would support a single field tsdocFlavor that helps tooling to recognize custom extensions to the core TSDoc tags. In the future it might include other fields such as a version number. See this file for a real world prototype of this convention.

Does this seem like a good design?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:23 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
octogonzcommented, Nov 16, 2019

We could also shorten the name from tsdoc-config.json to tsdoc.json.

2reactions
octogonzcommented, Nov 14, 2019

I also want to make it an array so you can use extends to “mixin” more than one family of custom tags. For example “I want API Extractor’s tags plus the tags for my documentation tool.”

Read more comments on GitHub >

github_iconTop Results From Across the Web

Approach - TSDoc
json metadata that enables tooling to detect whether a dependency's *.d.ts doc comments should be parsed as TSDoc or not. Open standard: TSDoc...
Read more >
Project roadmap - TSDoc
Implement an ESLint plugin for validating TSDoc syntax; Introduce a tsdoc.json file format to enable custom tag definitions to be portable between tools;...
Read more >
How can I use TSDoc?
The NPM dependency report is an easy way to find tools that implement TSDoc. Even if you have not enabled a documentation tool...
Read more >
microsoft/tsdoc
If you are implementing a tool that needs to extract information from ... But we'll quickly notice some potential edge cases would not...
Read more >
TSDoc: @see
@see {@link ParsedUrl} for the returned data structure * @see {@link https://tools.ietf.org/html/rfc1738|RFC 1738} * for syntax * @see your developer SDK ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found