programming language, superset of JavaScript that compiles to JavaScript
Factsheet
Anders Hejlsberg,
Luke Hoban
Anders Hejlsberg,
Luke Hoban
Where can I find documentation for TypeScript's built-in types and standard library? - Stack Overflow
Where is the syntax for TypeScript comments documented? - Stack Overflow
AI documentation writer for TS and JS in VSCode
What tools do you use to generate docs for TS project?
Videos
Hi everyone! I'm new to typescript. I've been programming for a very very long time, but I haven't touched javascript since the Internet Explorer 6 days. I'm having a bit of trouble finding documentation for some of the operators, and I'm hoping someone can give me some direction.
One example is "nullish coalescing" operator. I can find it in the release notes for typescript 3.7, but I can't find it in the official reference manual. Same thing goes for the spread operator (...).
I understand that typescript is compiled to javascript, and MDN's documentation is pretty good around these things, but I can't find a central location for the typescript language specification. Does such a thing exist? Could someone point me to it?
Other than searching around on the internet, what does everyone else do? I'm very much used to using reference manuals for this sort of thing.
Thanks to all!
Current
The TypeScript team, and other TypeScript involved teams, created a TSDoc specification. https://tsdoc.org/
Example straight from the docs:
export class Statistics {
/**
* Returns the average of two numbers.
*
* @remarks
* This method is part of the {@link core-library#Statistics | Statistics subsystem}.
*
* @param x - The first input number
* @param y - The second input number
* @returns The arithmetic mean of `x` and `y`
*
* @beta
*/
public static getAverage(x: number, y: number): number {
return (x + y) / 2.0;
}
}
Past
TypeScript uses JSDoc. e.g.
/** This is a description of the foo function. */
function foo() {
}
To learn jsdoc : https://jsdoc.app/
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.
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;
}
Update November 2020
A website is now online with all the TSDoc syntax available (and that's awesome): https://tsdoc.org/
For reference, old answer:
The right syntax is now the one used by TSDoc. It will allow you to have your comments understood by Visual Studio Code or other documentation tools.
A good overview of the syntax is available here and especially here. The precise spec should be "soon" written up.
Another file worth checking out is this one where you will see useful standard tags.
Note: you should not use JSDoc, as explained on TSDoc main page: Why can't JSDoc be the standard? Unfortunately, the JSDoc grammar is not rigorously specified but rather inferred from the behavior of a particular implementation. The majority of the standard JSDoc tags are preoccupied with providing type annotations for plain JavaScript, which is an irrelevant concern for a strongly-typed language such as TypeScript. TSDoc addresses these limitations while also tackling a more sophisticated set of goals.