question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve developer experience setting up TypeScript with Sequelize

See original GitHub issue

What 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:closed
  • Created 4 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
matushorvathcommented, Oct 1, 2019

@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:

  • non-TS users get 320 kB of types installed automatically as part of the sequelize package
  • TS users get broken types that can’t be used unless you do manual steps, which is very nonstandard in npm world

I respectfully ask that you reconsider this approach.

2reactions
papbcommented, Apr 3, 2019

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 😬

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Sequelize with TypeScript - LogRocket Blog
Sequelize provides two ways to register models: using sequelize.define or extending the Sequelize model class. In this tutorial, we'll use the ...
Read more >
Using Sequelize With TypeScript: Basic Project Setup - YouTube
Sequelize #TypeScriptIn this video, we set up a project using Sequelize and TypeScript along with a Postgres database.
Read more >
Build Type Safe API with Sequelize TypeScript and Express.js
This experience is ideal because you can transition from JavaScript to TypeScript in a much more convenient way and without changing the stack....
Read more >
TypeScript - Sequelize
We're working hard on making Sequelize a breeze to use in TypeScript. Some parts are still a work in progress. We recommend using...
Read more >
How To Use Sequelize with Node.js and MySQL - DigitalOcean
In this section, you will connect the Node.js application to the MySQL database using Sequelize. To connect to the database, open server.js for ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found