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.

Missmatch between undefined/null

See original GitHub issue

In index.d.ts (around line 153) it is stated that findOne, findOneAndDelete, and findOneAndUpdate return a Promise of the collection type, or undefined.

But in fact all of these return null, not undefined when no document is found.

This is quite annoying when using TypeScript, since it will error with Object is possibly undefined if you do not check for this, but checking with !== undefined only calms typescript down. It does nothing at runtime. However, checking with != undefined, or checking if the object is truthy does work at both compiletime and runtime.

Issue Analytics

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

github_iconTop GitHub Comments

mathieudutourcommented, Jul 28, 2020

Absolutely yes

mathieudutourcommented, Jul 27, 2020

yep, totally ok 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

The undefined vs null Pitfall in Javascript - The Code Ship
A property that has no definition is undefined, which also means no value, no type and never been referenced before in the scope....
Read more >
Inconsistency between null and undefined · Issue #584 - GitHub
Hello. Great work. I'm running into following issue, given this entity class Ent { @PrimaryGeneratedColumn() id: number; @Column("varchar", ...
Read more >
javascript - Can someone explain this simple concept of null ...
Simply, == only checks for value, whereas === checks for value as well as type of data. Here undefined and null both means...
Read more >
7 Tips to Handle undefined in JavaScript - Dmitri Pavlutin
A detailed article about 'undefined' keyword in JavaScript. 7 tips on how to handle correctly 'undefined' and increase code durability.
Read more >
JavaScript Fundamentals: Checking for null and undefined
The primitive values null and undefined have a distinct difference that should be used. But how to you tell the difference between a...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found