microsoft / microsoft/TypeScript

Typecheck code blocks in jsdoc

Open
#62,383 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

🔍 Search Terms

jsdoc typecheck

✅ Viability Checklist
⭐ Suggestion

When a codeblock is created in jsdoc, apply typechecking on it as if it were part of the code in the file.

📃 Motivating Example

I create a method that has a non-trivial function signature (example is contrived)

type OtherType<TData> = { data: TData };
class Class<TData> {
  doSomething<TNewData extends TData>(arg: OtherType<TNewData>): void;
}

I would like to document the idiomatic usage in jsdoc

  /**
   * Does something, example:
   * ```ts
   * const cls = new Class<{ x: number }>();
   * cls.doSomething({ data: { x: 1, y: 2 } });
   * ```
   */

If the function signature or underlying types change in any way, the typechecker will tell me to update the usages, but not the example.
The example becomes outdated potentially unknowingly, potentially causing bad code that could have been prevented if the example was typechecked.

💻 Use Cases
  1. What do you want to use this for?

Typecheck code blocks in jsdoc

  1. What shortcomings exist with current approaches?

Relying on implementations as the idiomatic way when the example in the jsdoc is intended the be the idiomatic way.

  1. What workarounds are you using in the meantime?

Inspection

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files, tests, or entry points are named. Research should identify the JSDoc code-block and type-checking entry points, then define tests showing that examples are checked against surrounding declarations without changing emitted JavaScript.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers, documentation
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.