Hey.
I'm writing a tool that is able to run database migrations, just like sequelize-cli. This tool dynamically requires some migration files, that end up being like this :
module.exports = {
up: () => {},
down: () => {}
}
The migration script requires it, and then execute the according method. The up and down methods are then passed some arguments, like a Sequelize QueryInterface for example.
I'd like to statically annotate those arguments, to get some benefits like Visual Studio Code autocompletion inside migration files.
... but as for now, the trouble is "requiring the file holding the type definition"...
The only way I found to make this working is like this :
/* eslint-disable no-unused-vars */
const SequelizeQueryInterface = require('sequelize/lib/query-interface')
const Sequelize = require('sequelize')
/* eslint-enable no-unused-vars */
module.exports = {
/**
* @param {SequelizeQueryInterface} sqlQueryInterface
* @param {Sequelize} Sequelize
*/
up: (sqlQueryInterface, Sequelize) => {
// <-- Types hint in VS Code work here
},
/**
* @param {SequelizeQueryInterface} sqlQueryInterface
* @param {Sequelize} Sequelize
*/
down: ({ sqlQueryInterface, Sequelize }, { mongoConnection, Mongoose }) => {
// <-- Types hint in VS Code work here
}
}
As you can see, I'm forced to actually require the source file in order to "import" and then use its type definition.
The question is simple :
Is there a better way (not involving require) to tell JSDoc where to find the types ?
Hey.
I'm writing a tool that is able to run database migrations, just like sequelize-cli. This tool dynamically
requires some migration files, that end up being like this :The migration script requires it, and then execute the according method. The
upanddownmethods are then passed some arguments, like a SequelizeQueryInterfacefor example.I'd like to statically annotate those arguments, to get some benefits like Visual Studio Code autocompletion inside migration files.
... but as for now, the trouble is "requiring the file holding the type definition"...
The only way I found to make this working is like this :
As you can see, I'm forced to actually require the source file in order to "import" and then use its type definition.
The question is simple :
Is there a better way (not involving
require) to tell JSDoc where to find the types ?