Shared: Contracts
Conventions related to argument and return-value contracts. Applies across both functions and methods.
Use BooleanLike for boolean return values
- When returning a boolean, use the
BooleanLiketype. - To do so, define the
BooleanLike@typedefat the bottom of the file. - If the type is already defined as standard,
@typedefis unnecessary. - Follow the JSDoc convention ("Writing
@typedef") for the@typedefformat.
/**
* Check whether the value is valid.
*
* @param {{
* value: *
* }} params - Parameters.
* @returns {BooleanLike} Whether the value is valid.
*/
function isValid ({
value,
}) {
return value != null
}
// Defined at the bottom of the file
/**
* @typedef {*} BooleanLike
*/