You Might Not Need
(a pure JS alternative)
Darren DeRidder
@73rhodes
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"checkJs": true,
"target": "es2015"
},
"exclude": [
"node_modules/"
]
}
/**
* @typedef CoverageTotals
* @property {number} totalCoverItemScores
* @property {number} totalCoverItemWeights
*/
/** @type {coverageTotals} rc */
let rc = {
totalCoverItemScores: 0,
totalCoverItemWeights: 0
};
let auth = /** @type {typedefs.Person} */(book.author);
Note the parenthesis around expression being typecast.
/**
* @typdef FooAttributes
* @property {string} foo
* @property {number} fizz
*
* @typedef BarAttributes
* @property {string} bar
* @property {number} buzz
*
* @typdef {FooAtributes & BarAttributes} Foobar
*/
/**
* @file typdefs.js
*
* ... JSDoc typedefs
*/
module.exports = {}
Using it:
const typedefs = require("./typedefs");
npm install @types/node
Typescript / JSDoc typdefs can co-exist :-)
Typedef as one of several strings
/**
* @typedef {('assert' | 'cover' | 'assume')} AssertionKind
*/
Be careful declaring module exports. Intellisense has trouble recognizing some module export syntax.
// Borken.
module.exports = {
myMethodA,
myMethodB
};
// Not borken.
exports.myMethodA = myMethodA;
exports.myMethodB = myMethodB;
What about other IDEs?