I have a Node.js function to create an Express server.
I've added //@ts-check to the file so that VSCode lints and type-checks everything.
What is the correct way to document this createServer function?
I want to show that it returns a Promise which resolves an object containing an Express instance (app), and the Number (port)
If this is an anti-pattern, that would be nice to know as well.
//@ts-check
const express = require('express');
/**
* @param {Number} port
* @returns {Promise}
*/
function createServer(port) {
return new Promise((resolve, reject) => {
const app = express();
server = app.listen(port, () => {
resolve({app, port});
});
});
}
This compiles for me:
See the documentation page for more information.