Improve developer experience setting up TypeScript with Sequelize
See original GitHub issueWhat are you doing?
I’m adding sequelize as a reference to my package/project and compiling it with TypeScript.
What do you expect to happen?
A successful compilation
What is actually happening?
I’ve obtained some errors that told me some types were missing. I solved this adding them as dependencies. Should you include @types/bluebird and @types/validator on the sequelize package? The error was the following:
node_modules/sequelize/types/lib/promise.d.ts:2:27 - error TS7016: Could not find a declaration file for module ‘bluebird’. ‘C:/Users/X/Documents/Y/Z/node_modules/bluebird/js/release/bluebird.js’ implicitly has an ‘any’ type.
Try npm install @types/bluebird
if it exists or add a new declaration (.d.ts) file containing declare module 'bluebird';
2 import * as Bluebird from ‘bluebird’; ~~~~~~~~~~
node_modules/sequelize/types/lib/utils/validator-extras.d.ts:2:22 - error TS7016: Could not find a declaration file for module ‘validator’. ‘C:/Users/X/Documents/Y/Z/node_modules/validator/index.js’ implicitly has an ‘any’ type.
Try npm install @types/validator
if it exists or add a new declaration (.d.ts) file containing declare module 'validator';
2 import * as val from ‘validator’;
Dialect: mariadb Dialect version: XXX Database version: XXX Sequelize version: 5.2.8
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (8 by maintainers)
@papb If you don’t want to bloat the package for non-TS users, I suggest you separate the types to a
@types/sequelize
package and make that package depend on@types/bluebird
and@types/validator
. That would both provide working types and reduce bloat for non-TS users to a minimum.The way it is packaged now, we get the worst of both worlds:
sequelize
packageI respectfully ask that you reconsider this approach.
For TypeScript usage, you need to manually install the following packages:
@types/node
,@types/validator
and@types/bluebird
. This is documented on our TypeScript Tutorial.We know that this tutorial is a bit hard to find. This is already known and there is already an open PR to improve this: #10677
Thanks for using Sequelize 😬