raise a type error on attempt to strict-equal-compare a value of string | null to undefined
See original GitHub issuethe 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:
- Created 7 years ago
- Reactions:17
- Comments:6 (2 by maintainers)
Top 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 >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 FreeTop 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
Top GitHub Comments
experienced the same problem today: I refactored a
number|null
tonumber|undefined
and my code stopped to work because there were===null
checks still left behind.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:
A later condition was overlooked, and became always-true.