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.

Typing of findAll seems to be missing the support of undefined values in where

See original GitHub issue

Issue Description

When using sequelize with typescript, we run into the issue of not being able to use objects that have potentially undefined attributes for the where attribute of a findAll call.

What are you doing?

import Sequelize from 'sequelize';

class class user extends Sequelize.Model {
/* define your table here, it shouldn't matter for types */
}
const queryObj:{id:string, optionalValue?:string} = { id: 'someID'};

user.findAll({ where: queryObj }); // This is where the issue appears

What do you expect to happen?

According to my understanding of the discussion in issue #8583 the function should support undefined values as input. (If as null, or ignoring it completely, is irrelevant for this issue)

What is actually happening?

We get type errors, not allowing undefined values inside the whereobject.

Additional context

none

Environment

  • Sequelize version: 5.19.6
  • Node.js version: ^10, should not be relevant in any way
  • Operating System: OS X and WIN 10, should also make no difference
  • If TypeScript related: TypeScript version: 3.6.2

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. (if it is simply adjusting the types)
  • 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
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
papbcommented, Oct 22, 2019

Changing the typing would allow runtime errors through accidentally added keys, that have the value undefined though.

Personally I think this drawback is a small price to pay.

I’ve found typescript#13195 though, so I guess there isn’t a better way until that issue is fixed (if ever?).

Let’s see what @SimonSchick thinks about it 😃

0reactions
Altimar21commented, Apr 14, 2020

Hi ! Did you have time to check this one ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot convert undefined or null to object - Stack Overflow
Generic answer. This error is caused when you call a function that expects an Object as its argument, but pass undefined or null...
Read more >
How can I search for a null value? - Jira - Atlassian Community
Solved: As the subject states, I would like to search for tickets that have a null value in a particular field. For example,...
Read more >
cannot read properties of undefined (reading 'findall') - You.com
You're passing an empty object to User.findAll({}) in your UserController.js file. Try User.findAll() , instead.
Read more >
Handling Missing Data | Python Data Science Handbook
Missing Data in Pandas​​ The way in which Pandas handles missing values is constrained by its reliance on the NumPy package, which does...
Read more >
Why do I get the error "Unrecognized function or variable"?
Help ! I received "undefined function 'string2char' for 'char' type input arguments" ...
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