EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials TypeScript Tutorial TypeScript JSDoc
Secondary Sidebar
TypeScript Tutorial
  • TypeScript Basic and Advanced
    • What is TypeScript?
    • Typescript Examples
    • TypeScript Versions
    • TypeScript Operators
    • JavaScript dump object
    • JavaScript get Method
    • Webpack ReactJS
    • Code Generator JavaScript
    • JavaScript Projects
    • Call Stack JavaScript
    • JavaScript Projects GitHub
    • JavaScript Filter Function
    • JavaScript nan
    • JavaScripttimestamp
    • TypeScript loop
    • CoffeeScript
    • TypeScript Webpack
    • setTimeout TypeScript
    • DHTMLX
    • CoffeeScript for loop
    • TypeScript number
    • JavaScript export module
    • TypeScript string contains
    • TypeScript Inheritance
    • TypeScript get
    • TypeScript undefined
    • TypeScript Global Variable
    • TypeScript Dictionary
    • TypeScript Generic
    • TypeScript Cast Object
    • TypeScript Optional Parameters
    • TypeScript? switch
    • TypeScript promise
    • TypeScript tuple
    • TypeScript Hashmap
    • TypeScript let
    • TypeScript Getter
    • TypeScript Pattern Matching
    • TypeScript number to string
    • TypeScript substring
    • TypeScript?lambda
    • TypeScript UUID
    • TypeScript JSDoc
    • TypeScript Decorators
    • Typescript for loop
    • TypeScript HTTP Request
    • TypeScript Abstract Class
    • TypeScript Question Mark
    • TypeScript Nullable
    • TypeScript reduce
    • TypeScript Mixins
    • TypeScript keyof
    • TypeScript string to number
    • TypeScript JSON parse
    • TypeScript const
    • TypeScript declare module
    • TypeScript String
    • TypeScript filter
    • TypeScript Multiple Constructors
    • TypeScript? Set
    • TypeScript string interpolation
    • TypeScript instanceof
    • TypeScript JSON
    • TypeScript Arrow Function
    • TypeScript generator
    • TypeScript namespace
    • TypeScript default parameter
    • TypeScript cast
    • TypeScript babel
    • Typescript Key-Value Pair
    • TypeScript if
    • TypeScript keyof Enum
    • TypeScript wait
    • TypeScript Optional Chaining
    • TypeScript JSX
    • TypeScript Version Check
    • TypeScript Unit Testing
    • TypeScript Handbook
    • TypeScript module
    • TypeScript Extend Interface
    • TypeScript npm
    • TypeScript pick
    • TypeScript Interface Default Value
    • JavaScript import module
    • Obfuscate Javascript
    • TypeScript basics
    • setInterval TypeScript
  • Type of Union
    • TypeScript Object Type
    • TypeScript type check
    • TypeScript promise type
    • TypeScript JSON type
    • TypeScript Union Types
    • TypeScript typeof
    • TypeScript Types
  • TypeScript Array
    • TypeScript Array of Objects
    • Methods TypeScript Array
    • TypeScript remove item from array
    • TypeScript add to array
    • TypeScript Array Contains
  • Function Of Array
    • TypeScript Function Interface
    • TypeScript Functions
    • TypeScript Export Function
    • TypeScript function return type

TypeScript JSDoc

TypeScript JSDoc

Introduction to TypeScript JSDoc

The Application Programming Interface documentation generator for TypeScript is JSDoc. In which the documentation comments are directly added to the source code on the right side of the code itself and there is a JSDoc tool to scan the source code and generate the HTML documentation and the purpose of JSDoc is to document the TypeScript library and by using JSDoc modules, classes, namespaces, methods, method parameters etc. can be documented and each comment in a JSDoc should begin with /** and end with */ otherwise the comment will not be recognized by the JSDoc parser and those beginning with /* or /*** will be ignored by the parser.

Syntax to declare a comment in TypeScript class:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

** comment1
*comment2
*comment3
*commentn
*/

Where comment1, comment2, comment3, commentn are the comments to be included in a TypeScript program.

Working of JSDoc or Comments in TypeScript

  • The Application Programming Interface documentation generator for TypeScript is JSDoc in which the documentation comments are directly added to the source code on the right side of the code itself.
  • There is a JSDoc tool to scan the source code and generate the HTML documentation.
  • The purpose of JSDoc is to document the TypeScript library and by using JSDoc modules, classes, namespaces, methods, method parameters etc. can be documented.
  • Each comment in a JSDoc should begin with /** and end with */ otherwise the comment will not be recognized by the JSDoc parser and those beginning with /* or /*** will be ignored by the parser.

Examples of TypeScript JSDoc

Given below are the examples of TypeScript JSDoc:

Example #1

TypeScript program to demonstrate JSDoc or the comments section to describe the functionality of the program along with the parameters using which we compute the power of a given number and display the output on the screen.

Code:

/** defining an anonymous function using arrow function to compute the power of a number and display the result as the output on the screen
*/
let power = (firstnum:number, secondnum:number) : number => {
return Math.pow(firstnum, secondnum);
}
console.log('The result when the given number is raised to the power of 2 is: ');
console.log(power(10,2));

Output:

TypeScript JSDoc 1

In the above program, the comments section is described between the symbols /** and */. Then we are defining an anonymous function using arrow function to compute the power of given number and display the result as the output on the screen.

Example #2

TypeScript program to demonstrate JSDoc or the comments section to describe the functionality of the program along with the parameters using which we compute the power of a given number and display the output on the screen.

Code:

/**
*Computes the power of a given number
*@constructor
*@param {number} firstnum – The number whose power raised to 2 must be found
*@param {number} secondtnum – The number 2 to which the given number must be raised to.
*/
function power(firstnum:number, secondnum:number)
{
let result = Math.pow(firstnum, secondnum);
return result;
}
console.log('The result when the given number is raised to the power of 2 is: ');
console.log(power(10,2));

Output:

TypeScript JSDoc 2

In the above program, the comments section is described between the symbols /** and */ in which we have defined that there is a function using @constructor and the parameters are defined with their datatypes using @param. Then we are defining a function using to compute the power of given number and display the result as the output on the screen.

Example #3

TypeScript program to demonstrate JSDoc or the comments section to describe the functionality of the program along with the parameters using which we compute the square root of a given number and display the output on the screen.

Code:

/**
*Computes the square root of a given number
*@constructor
*@param {number} firstnum – The number whose square root must be found
*/
function squareroot(firstnum:number)
{
let result = Math.sqrt(firstnum);
return result;
}
console.log("The square root of the given number is:\n", squareroot(4);

Output:

square root

In the above program, the comments section is described between the symbols /** and */ in which we have defined that there is a function using @constructor and the parameters are defined with their datatypes using @param. Then we are defining a function to compute the square root of a given number and display the result as the output on the screen.

Example #4

TypeScript program to demonstrate JSDoc or the comments section to describe the functionality of the program along with the parameters using which we compute the factorial of a given number and display the output on the screen.

Code:

/**
*Computes the factorial of a given number
*@constructor
*@param {number} firstnum – The number whose factorial must be found
*/
var fact:number = 1;
function factorial(firstnum:number)
{
for(let u =firstnum; u>=1; u--)
{
fact = fact * u;
}
return fact;
}
console.log("The factorial of the given number is:\n", factorial(5);

Output:

functionality of the program

In the above program, the comments section is described between the symbols /** and */ in which we have defined that there is a function using @constructor and the parameters are defined with their datatypes using @param. Then we are defining a function to compute the factorial of a given number and display the result as the output on the screen.

Rules and Regulations for JSDoc or Comments

Given below are the Rules and Regulations for JSDoc or Comments in TypeScript:

  • A comment in TypeScript should begin with the symbol /**.
  • A comment in TypeScript should end with symbol */.
  • Comments beginning or ending with other symbols are not recognized by the JSDoc parser.
  • A function must be represented within the comment section by using @constructor.
  • The parameters must be represented along with their data types within the comment section by using @param followed by their data type in curly brackets.

Recommended Articles

We hope that this EDUCBA information on “TypeScript JSDoc” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. TypeScript let
  2. TypeScript typeof
  3. TypeScript Generic
  4. TypeScript Versions
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more