Quantcast
Channel: Active questions tagged visual-studio-code - Stack Overflow
Viewing all articles
Browse latest Browse all 98452

JSDoc typedef declaration for moment.js object

$
0
0

I have a function that uses moment.js. I am new to typescript and jsdoc imports and I'm wondering how I can document that a function returns, specifically a moment object:

const moment = require('moment-timezone');
/**
 * @typedef Moment
 * @property {import('moment-timezone').Moment} moment
 */

/**
 * Returns a moment object with the date / time converted to the given timezone
 * @param {Date} dateTime
 * @param {string} targetTimeZone
 * @return {Moment} 
 */
const convertDateTimeToLocationTimeZone = (dateTime, targetTimeZone) => {
    return moment(dateTime).tz(targetTimeZone);
};

I'm not even sure if the above is totally off - but also the above gives me this error in vscode:

Property 'moment' is missing in type 'import("/Users/Deb/Desktop/project/node_modules/moment/....").Moment' but required in type 'import("/Users/Deb/Desktop/project/...").Moment'.

Note, I do have @types/moment-timezone installed.


Viewing all articles
Browse latest Browse all 98452

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>