Typing of findAll seems to be missing the support of undefined values in where
See original GitHub issueIssue 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 where
object.
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:
- Created 4 years ago
- Comments:6 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 😃
Hi ! Did you have time to check this one ?