Convert Figma logo to code with AI

microsoft logotsdoc

A doc comment standard for TypeScript

4,733
131
4,733
140

Top Related Projects

7,696

Documentation generator for TypeScript projects.

15,011

An API documentation generator for JavaScript.

:book: documentation for modern JavaScript

9,721

RESTful web API Documentation Generator.

27,539

🃏 A magical documentation site generator.

Quick Overview

TSDoc is a proposal for standardizing TypeScript's documentation comments. It aims to provide a consistent syntax for documenting TypeScript code, making it easier for developers to write and maintain documentation, and for tools to parse and generate documentation from code comments.

Pros

  • Provides a standardized approach to TypeScript documentation
  • Improves consistency across projects and teams
  • Enables better tooling support for generating and parsing documentation
  • Enhances code readability and maintainability

Cons

  • Requires learning and adopting a new syntax for documentation
  • May require updating existing documentation to conform to the new standard
  • Some developers might find the syntax overly verbose or restrictive
  • Limited adoption compared to other documentation standards like JSDoc

Code Examples

Here are a few examples of TSDoc syntax:

  1. Documenting a function:
/**
 * Calculates the sum of two numbers.
 * @param a - The first number to add.
 * @param b - The second number to add.
 * @returns The sum of the two numbers.
 */
function add(a: number, b: number): number {
  return a + b;
}
  1. Documenting a class:
/**
 * Represents a person with a name and age.
 */
class Person {
  /**
   * Creates a new Person instance.
   * @param name - The person's name.
   * @param age - The person's age.
   */
  constructor(public name: string, public age: number) {}

  /**
   * Greets the person.
   * @returns A greeting message.
   */
  greet(): string {
    return `Hello, my name is ${this.name} and I'm ${this.age} years old.`;
  }
}
  1. Using TSDoc tags:
/**
 * Represents a book.
 * @remarks
 * This class is part of the library management system.
 * @example
 * ```typescript
 * const book = new Book("The Great Gatsby", "F. Scott Fitzgerald", 1925);
 * console.log(book.getInfo());
 * ```
 */
class Book {
  /**
   * Creates a new Book instance.
   * @param title - The book's title.
   * @param author - The book's author.
   * @param year - The year the book was published.
   */
  constructor(
    public title: string,
    public author: string,
    public year: number
  ) {}

  /**
   * Gets information about the book.
   * @returns A string containing the book's title, author, and publication year.
   */
  getInfo(): string {
    return `${this.title} by ${this.author} (${this.year})`;
  }
}

Getting Started

To start using TSDoc in your TypeScript project:

  1. Install the TSDoc parser (optional):

    npm install --save-dev @microsoft/tsdoc
    
  2. Configure your TypeScript compiler options to use TSDoc:

    {
      "compilerOptions": {
        "plugins": [
          { "name": "@microsoft/tsdoc-plugin" }
        ]
      }
    }
    
  3. Start writing TSDoc comments in your TypeScript files using the /** syntax.

  4. Use TSDoc-aware tools like API Extractor or TypeDoc to generate documentation from your comments.

Competitor Comparisons

7,696

Documentation generator for TypeScript projects.

Pros of TypeDoc

  • More mature and widely adopted project with a larger community
  • Generates comprehensive HTML documentation out-of-the-box
  • Supports plugins for extended functionality

Cons of TypeDoc

  • Heavier and more complex to set up and configure
  • May produce overly verbose output for simpler projects

Code Comparison

TypeDoc example:

/**
 * Calculates the sum of two numbers.
 * @param a The first number.
 * @param b The second number.
 * @returns The sum of a and b.
 */
function add(a: number, b: number): number {
    return a + b;
}

TSDoc example:

/**
 * Calculates the sum of two numbers.
 * @param a - The first number.
 * @param b - The second number.
 * @returns The sum of a and b.
 */
function add(a: number, b: number): number {
    return a + b;
}

Summary

TypeDoc is a more feature-rich documentation generator, ideal for larger projects requiring detailed HTML output. TSDoc, on the other hand, focuses on standardizing TypeScript documentation comments and is lighter weight. While both use similar comment syntax, TypeDoc offers more out-of-the-box functionality, whereas TSDoc provides a foundation for building custom documentation tools.

15,011

An API documentation generator for JavaScript.

Pros of JSDoc

  • Mature and widely adopted documentation system with a large community
  • Supports multiple JavaScript environments (browser, Node.js, etc.)
  • Extensive set of tags for documenting various code elements

Cons of JSDoc

  • Less TypeScript-specific features and integration
  • Can be more verbose and require more manual type annotations
  • May not fully leverage TypeScript's static typing capabilities

Code Comparison

JSDoc:

/**
 * @param {string} name - The name of the person
 * @param {number} age - The age of the person
 * @returns {Object} An object containing the person's details
 */
function createPerson(name, age) {
  return { name, age };
}

TSDoc:

/**
 * Creates a person object
 * @param name - The name of the person
 * @param age - The age of the person
 * @returns An object containing the person's details
 */
function createPerson(name: string, age: number): { name: string; age: number } {
  return { name, age };
}

TSDoc leverages TypeScript's type system, resulting in more concise documentation and better integration with TypeScript tooling. JSDoc requires explicit type annotations in comments, while TSDoc can infer types from the TypeScript code itself.

:book: documentation for modern JavaScript

Pros of documentation

  • Supports multiple programming languages, including JavaScript, TypeScript, and Flow
  • Offers various output formats, including HTML, Markdown, and JSON
  • Has a more established ecosystem with plugins and themes

Cons of documentation

  • Less focused on TypeScript-specific features and syntax
  • May require more configuration for complex TypeScript projects
  • Not as tightly integrated with the TypeScript compiler

Code comparison

documentation:

/**
 * Calculates the sum of two numbers
 * @param {number} a - The first number
 * @param {number} b - The second number
 * @returns {number} The sum of a and b
 */
function add(a, b) {
  return a + b;
}

TSDoc:

/**
 * Calculates the sum of two numbers
 * @param a - The first number
 * @param b - The second number
 * @returns The sum of a and b
 */
function add(a: number, b: number): number {
  return a + b;
}

The main difference in the code examples is that TSDoc leverages TypeScript's built-in type annotations, resulting in cleaner and more concise documentation. documentation requires explicit type declarations in the JSDoc comments, which can lead to redundancy in TypeScript projects.

9,721

RESTful web API Documentation Generator.

Pros of apiDoc

  • Supports multiple programming languages, not limited to TypeScript
  • Generates a standalone HTML documentation website
  • Offers a wide range of customization options for output

Cons of apiDoc

  • Requires separate comments for documentation, potentially leading to duplication
  • Less integrated with the TypeScript ecosystem
  • May require more manual effort to keep documentation in sync with code changes

Code Comparison

TSDoc example:

/**
 * Calculates the sum of two numbers.
 * @param a - The first number
 * @param b - The second number
 * @returns The sum of a and b
 */
function add(a: number, b: number): number {
  return a + b;
}

apiDoc example:

/**
 * @api {get} /user/:id Request User information
 * @apiName GetUser
 * @apiGroup User
 *
 * @apiParam {Number} id Users unique ID.
 *
 * @apiSuccess {String} firstname Firstname of the User.
 * @apiSuccess {String} lastname  Lastname of the User.
 */

TSDoc focuses on inline documentation for TypeScript code, while apiDoc uses separate comment blocks to generate API documentation. TSDoc integrates more seamlessly with TypeScript development, whereas apiDoc offers broader language support and generates standalone documentation websites.

27,539

🃏 A magical documentation site generator.

Pros of Docsify

  • Lightweight and easy to set up with minimal configuration
  • Supports multiple themes and plugins for customization
  • Generates documentation on-the-fly without building static HTML files

Cons of Docsify

  • Limited support for TypeScript-specific documentation features
  • May require more manual effort for complex documentation structures
  • Less integrated with TypeScript development workflows

Code Comparison

TSDoc example:

/**
 * Calculates the sum of two numbers.
 * @param a - The first number
 * @param b - The second number
 * @returns The sum of a and b
 */
function add(a: number, b: number): number {
  return a + b;
}

Docsify example:

# My Documentation

## Function: add

Calculates the sum of two numbers.

**Parameters:**
- `a`: The first number
- `b`: The second number

**Returns:** The sum of a and b

TSDoc is specifically designed for TypeScript documentation, providing structured comments that integrate well with TypeScript tooling. Docsify, on the other hand, is a more general-purpose documentation generator that focuses on simplicity and flexibility, making it suitable for various project types beyond just TypeScript.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

https://tsdoc.org/

#tsdoc chat room   Build Status

Documentation Links

Projects in this monorepo

FolderVersionChangelogDescription
/api-demo(local project)Code samples illustrating how to use the @microsoft/tsdoc parser
/eslint-pluginnpm versionchangelogeslint-plugin-tsdoc plugin for ESLint
/playground(local project)Source code for the TSDoc Playground web app
/tsdocnpm versionchangelog@microsoft/tsdoc parser library
/tsdoc-confignpm versionchangelog@microsoft/tsdoc-config loader for tsdoc.json

Contributor Notice

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

NPM DownloadsLast 30 Days