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.

Property 'QueryTypes' does not exist on type 'Sequelize'.

See original GitHub issue

Issue Description

Type script error for raw queries after upgrade to v5 and removing @types/sequelize from dependencies.

What are you doing?

const { Sequelize } = require('sequelize');
const sequelize = new Sequelize(...);
sequelize.query('SELECT ...', { type: sequelize.QueryTypes.SELECT });

What do you expect to happen?

Code should continue to compile.

What is actually happening?

Typescript compiler error:

Property 'QueryTypes' does not exist on type 'Sequelize'.

Environment

  • Sequelize version: 5.19.2
  • Node.js version: 12
  • Operating System: MacOS
  • If TypeScript related: TypeScript version: 3.6.3

Issue Template Checklist

How does this problem relate to dialects?

  • I think this problem happens regardless of the dialect.
  • I think this problem happens only for the following dialect(s):
  • I don’t know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I don’t know how to start, I would need guidance.
  • No, I don’t have the time, although I believe I could do it if I had the time…
  • No, I don’t have the time and I wouldn’t even know how to start.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
papbcommented, Oct 4, 2019

Fair enough, but there is likely a lot of existing code that uses the documented code in my report. Maybe a documentation update is necessary?

Yup, I’m working on it (I’m working on a major docs rewrite actually)! Stay tuned.

Also, just because the type isn’t declared, that object still exists at runtime which is going to encourage casting and the loss of type safety you’d generally expect from Typescript.

I disagree, when people try to use TypeScript and get this error, like you did, they can fix it by casting (bad, as you said), or change it to the clean solution:

const { Sequelize, QueryTypes } = require('sequelize');
const sequelize = new Sequelize(...);
sequelize.query('SELECT ...', { type: QueryTypes.SELECT });

I’ll leave this open as a WIP docs issue

0reactions
ephyscommented, Oct 6, 2022

The current documentation uses const { QueryTypes } = require('sequelize');, I’ll close this now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Property 'Op' does not exist on type 'typeof Sequelize'
I'm getting this error on build using tsc. import { Sequelize } from 'sequelize-typescript';.
Read more >
How to use QueryTypes function in Sequelize - Tabnine
models.sequelize.query(request, {type: models.sequelize.QueryTypes.SELECT}).then(function(result){ if(result.length > 0)
Read more >
TypeScript - Sequelize
As Sequelize heavily relies on runtime property assignments, TypeScript won't be very useful out of the box. A decent amount of manual type...
Read more >
sequelize-typescript - npm
Start using sequelize-typescript in your project by running `npm i ... If the type cannot or should not be inferred, use:.
Read more >
How To Use Sequelize with Node.js and MySQL - DigitalOcean
Note: You can manage model synchronization by passing force parameters to force the creation of a new table if it does not exist, ......
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