๐JSDoc
TypeScript โฉ JSDoc Reference
if you write three or more stars (*), the comment will be ignored;
/** <-- โญ๏ธ JSDoc expects two stars (no more, no less)
*
*/
TypeScript in 50 Lessons (2020), Lesson 4: Adding Types with JSDoc
Modern JavaScript Web Development Cookbook (2018) โฉ Documenting your code with JSDoc
Google Apps Script โฉ play JSDoc
GitHub โฉ vscode-docthis - auto-generated JSDoc.
VSCode โฉ Document This (vscode-docthis?)
DevHints โฉ JSDoc cheatsheet
/**
* Adds VAT to a price
*
* @param {number} price The price without VAT
* @param {number} vat The VAT [0-1]
*
* @returns {number}
*/
function addVAT(price, vat = 0.2) {
return price * (1 + vat)
}
// defining objects
/**
* @typedef {Object} Article
*
* @property {number} price
* @property {number} vat
* @property {string} string
* @property {boolean=} sold (โญ๏ธ optional property)
*/
// โญ๏ธ optional property/parameter syntax:
// โข @param {boolean=} sold
// โข @param {boolean} [sold]
/**
* Now we can use `Article` as a proper type
*
* @param {[Article]} articles
*/
function totalAmount(articles) {
return articles.reduce((total, article) => {
return total + addVAT(article) }, 0)
}
// inline types
/**
* @type {number}
*/
let amount;
// defining functions (@callback works like @typedef)
/**
* @callback LoadingCallback
*
* @param {number} status
* @param {string=} response (โญ๏ธ optional, see: @typedef)
* @returns {void}
*/
/**
* @param {string} url
* @param {LoadingCallback} cb
*/
function loadData(url, cb) {
const xhr = new XMLHttpRequest();
xhr.open('GET', url)
xhr.onload = () => {
cb(xhr.status, xhr.responseText)
}
}
// imports `Article` type from `article.ts`
// and makes it available under `Article`
/**
* @typedef { import('./article').Article } Article
*/
/**
* @type {Article}
*/
const article = {
title: 'The best book in the world',
price: 10,
vat: 0.2
}
// import from `types.d.ts` type declaration file
/**
* @typedef { import('./types.d').ShipStorage } ShipStorage
*/
Last updated