Exploring TypeScript and JsDoc has been on my to-do list. Occasionally, I find myself mixing numeric values that aren't quite compatible. Let's consider a hypothetical situation where I mix milliseconds and seconds. In the script below, I've attempted to utilize JsDoc for guidance. While editing in Visual Studio Code, I expected to receive warnings or errors but nothing appeared.
// @ts-check
/** @typedef {number} TSseconds */
/** @typedef {number} TSmilliSeconds */
/** @type {TSmilliSeconds} */
let ms = 1;
/** @type {TSseconds} */
let sec = 2;
ms = sec;
/**
*
* @param {TSseconds} secVal
* @returns {TSmilliSeconds}
*/
function sec2ms(secVal) {
console.log("sec2ms", secVal);
return 1000 * secVal;
}
/** @type {TSmilliSeconds} */
let ms2;
ms2 = sec2ms(ms);
/** @type {TSseconds} */
let sec2;
sec2 = sec2ms(ms);
It seems like I may have misunderstood something. How can I enhance the support from JsDoc here? (Code completion is functional.)
I currently have Typescript installed (npm install -g typescript
) along with the latest stable version of NodeJs.