TSDoc Comments
A TSDoc comment is a multiline comment that documents the purpose and usage of your code.
In this case, we'll specify that the function "Adds two numbers together". We can also use an @example
tag to show an example of how the function is used:
/** * Adds two numbers together. * @
Transcript
00:00 Okay, let's do it. Here's one I prepared earlier. I'm going to add a comment above this that just says it adds two numbers together. And it's also got this little example tag too, which I'll show you in a second. And now whenever I use my function here, I'll call it with, you know, two numbers here. First of all, what we see is when we go to actually type
00:18 in the numbers here, it shows us exactly the signature of the function we expect. And it gives us the comment there immediately adds two numbers together. And we've even got an example usage with full syntax highlighting as well. How amazing is that? So this example
00:35 tag basically means that anything below the example will be considered an example and it will be syntax highlighted. So we can even add some stuff in here saying, wow, so cool. And it will be shown. Where is it? Just here. There you go. It's getting a bit crowded here because we've got the error translations coming in as well. So this one here, it says my function
00:55 adds two numbers together example. And it's even got the syntax highlighted stuff at the bottom too. So this was actually one of the reasons I fell in love with TypeScript. First of all, is because it just gives you so many tools to really say what your code is doing to other people and communicate. But of course, that's only present if you know how to hover
01:14 these and how you, how to introspect all of this information, but so, so gorgeous. So if you're building any kind of library or even some util functions that are designed to be consumed by other people and used by other people, and of course, whose code is just designed to be used by themselves, you know, you're all working in teams professionally,
01:31 then you know, js.comments, cs.comments, there's a whole world of stuff out there that you can look at to kind of bring this information front and center when people are using your code.