microsoft / microsoft/tsdoc

[Question] Is there a way to generate the "@example" tag contents from an external source file?

Open
#344 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
5k
Forks
162
Avg merge
17h 24m
Merged PRs (30d)
8

Description

For example,

Here's the source file:

/* source/add.ts */

/**
 * Adds two numbers.
 *
 * @param x - First number.
 * @param y - Second number
 * @returns The sum of x and y.
 */
const add = (x: number, y: number): number => x + y

Here's the example source file:

/* examples/add.ts */

import { add } from '@source/add'

add(2, 3) // 5

Is there a way to reference the example source file in TSDoc?

Ideally via something like this:

/* pseudo-code */

/**
 * @example {@ref(./examples/add.ts)}
 */

The key benefit to have such ability is to have a single source of example without any duplications to be able to present it in a multiple ways simultaneously, like running it and listing its source at the same time.

Contributor guide

No contributing guide indexed for this repository

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

Start by reviewing the TSDoc @example tag and the source/add.ts and examples/add.ts examples described in the issue. Determine how an external-file reference would preserve one example source for both execution and displayed documentation. Done means the supported behavior and its limitations are defined clearly enough to document or implement.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.