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.

require explicit check for undefined?

See original GitHub issue

This code has a runtime error. It will not use the 0 value.

Should Hegel force us to explicitly check undefined to avoid the runtime error?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
phauxcommented, May 23, 2020

I think it would make sense to warn on Nullish | PossblyFalsy used in if, while, ternary, etc. (where Nullish is either null or undefined or union of both, and PossiblyFalsy is any combination of string, number, bigint and boolean)

This is what Flow does (with sketchy-null lint enabled), and there’s strict-boolean-expressions for typescript-eslint which also does that.

0reactions
trusktrcommented, May 29, 2020

I don’t think a linter could do a good job checking these things, otherwise the linter would become something like Hegel already is.

Read more comments on GitHub >

github_iconTop Results From Across the Web

explicit typeof == "undefined" check vs just checking for its ...
The first explicitly checks that x.foo is undefined , whereas if (x.foo) is checking to see if x.foo is truthy.
Read more >
Checking for undefined: === versus typeof versus falsiness
There are several ways of checking whether a variable has the value undefined. This blog post explains the differences.
Read more >
How to check for undefined in JavaScript
Generally, comparing directly to undefined is still safe. There's no practical reason for an application to re-assign the value of undefined .
Read more >
Null vs. Undefined - TypeScript Deep Dive - Gitbook
Checking for either. Fact is you will need to deal with both. Interestingly in JavaScript with == , null and undefined are only...
Read more >
Documentation - TypeScript 2.0
In strict null checking mode the compiler requires every reference to a local variable of a type that doesn't include undefined to be...
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