The question Document destructured function parameter in JSDoc hints at this, but doesn't explicitly ask about the optional parameter in the question. And also, I don't think they're using VSCode type checking?
I'm getting this error when VSCode is type checking my JavaScript project for me:
(parameter) rejectMsg: string
Type '{}' is missing the following properties from type '{ rejectMsg: string; windowSize: number; stallLimit: number; }
': rejectMsg, windowSize, stallLimitts(2739)
The code in question is:
/**
* Function that wraps the on 'data' callback of a Stream, and monitors for 'stalling'.
*
* @param {(data)=>void} [successCb] callback run on successful chunk of data
* @param {{rejectMsg: string, windowSize: number, stallLimit: number}} [param1] options
* @returns {(data)=>void}
*/
const stallGuard = (successCb = () => { }, { rejectMsg = 'Stalled', windowSize = 5, stallLimit = windowSize } = {}) => {
// code goes here
}
If I don't put the default param for those options (= {}
) then it barfs when I call without any options passed in.
Is there a way of satisfying the type checking for this?