Where is the syntax for TypeScript comments documented?

前端 未结 5 810
执念已碎
执念已碎 2020-12-04 11:30

Is the syntax for TypeScript comments documented anywhere?

And by any chance, does it now support the C# /// system?

5条回答
  •  旧时难觅i
    2020-12-04 12:30

    Future

    The TypeScript team, and other TypeScript involved teams, plan to create a standard formal TSDoc specification. The 1.0.0 draft hasn't been finalised yet: https://github.com/Microsoft/tsdoc#where-are-we-on-the-roadmap

    Current

    TypeScript uses JSDoc. e.g.

    /** This is a description of the foo function. */
    function foo() {
    }
    

    To learn jsdoc : https://jsdoc.app/

    Demo

    But you don't need to use the type annotation extensions in JSDoc.

    You can (and should) still use other jsdoc block tags like @returns etc.

    Example

    Just an example. Focus on the types (not the content).

    JSDoc version (notice types in docs):

    /**
     * Returns the sum of a and b
     * @param {number} a
     * @param {number} b
     * @returns {number}
     */
    function sum(a, b) {
        return a + b;
    }
    

    TypeScript version (notice the re-location of types):

    /**
     * Takes two numbers and returns their sum
     * @param a first input to sum
     * @param b second input to sum
     * @returns sum of a and b
     */
    function sum(a: number, b: number): number {
        return a + b;
    }
    

提交回复
热议问题