DEV Community

Anthony Petrides
Anthony Petrides

Posted on

TS: Documenting Functions

A useful feature in TypeScript that I seemed to have glossed over in my learnings has been 'documentation comments'.

In short, they enable you document functions in a clean and simply way and is understood by modern code editors such as VS Code.

Take the below function to demonstrate:

 * Adds 2 numbers together
 * @param value1 - The first number
 * @param value2 - The second number
 * @returns Returns the sum of 2 numbers
const sumIt = (value1: number, value2: number): number => {
  return value1 + value2;
Enter fullscreen mode Exit fullscreen mode

If you open this in VS Code as a .ts file, then hover over your function name, you get the following interation:

Similarly, if you simply hover over one of the function arguments, you get the documentation comment specific to that argument:


To close, I find this a pretty awesome feature for situations where you may have a particularly complex function, where some human readable and interactive comments can really help to self-document and reduce complexity.

Top comments (0)