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.

raise a type error on attempt to strict-equal-compare a value of string | null to undefined

See original GitHub issue

the following examples are almost certainly bugs:

declare var one: string | undefined;
// expected a type error: Operator '===' cannot be applied to types 'string | undefined' and 'null'
// actual no problem
if (one === null) { 
   // unreachable, because one can't ever be null, undefined was likely meant instead
}
declare var another: string | null;
// expected a type error: Operator '===' cannot be applied to types 'string | null' and 'undefined'
// actual no problem
if (another === undefined) {
   // unreachable, because one can't ever be undefined, null was likely meant instead
}

consider raising a type error for the above situations

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:17
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
nippur72commented, Apr 25, 2017

experienced the same problem today: I refactored a number|null to number|undefined and my code stopped to work because there were ===null checks still left behind.

0reactions
jfirebaughcommented, Jul 31, 2019

Ironically, I work on a codebase where we’re incrementally enabling strictNullChecks and was bit by this.

To support strictNullChecks , the following change was made:

- let applyMemoryInitializer: () => void;
+ let applyMemoryInitializer: (() => void) | null = null;

A later condition was overlooked, and became always-true.

if (applyMemoryInitializer !== undefined) {
   ...
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to suppress "error TS2533: Object is possibly 'null' or ...
One way to fix this is to ensure that the values are never null or undefined , for example by initialising them up...
Read more >
strictNullChecks - TSConfig Option - TypeScript
When strictNullChecks is true , null and undefined have their own distinct types and you'll get a type error if you try to...
Read more >
SQL error messages and exceptions - Oracle Help Center
22005, An attempt was made to get a data value of type ' <datatypeName> ... 22501, An ESCAPE clause of NULL returns undefined...
Read more >
Null and undefined (Reference) - Prisma
How Prisma Client handles null and undefined, including a GraphQL use case. ... an error in this scenario: Type 'null' is not assignable...
Read more >
TypeError: "x" has no properties - JavaScript - MDN Web Docs
The JavaScript exception "null (or undefined) has no properties" occurs when you attempt to access properties of null and undefined.
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