How to check for undefined
#442
Closed
mxdvl
started this conversation in
Team Posts
Replies: 2 comments
-
great digging, thanks! |
Beta Was this translation helpful? Give feedback.
0 replies
-
for future travellers guardian/libs#211 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
There are currently three ways of checking whether a value is
undefined
in JavaScript:We use the last two in our codebases, but thankfully since ES5 the global
undefined
cannot be redefined. It can still be shadowed, but the recommended ESLint rules prevent this viano-shadow-restricted-names
.Due to this, I believe it is not necessary to enforce this rule globally.
Appendix
To get TypeScript to play nice, you need to use type predicates and pass it as the filter. And here’s a working example.
Beta Was this translation helpful? Give feedback.
All reactions