unicorn/no-null Style
What it does
Disallow the use of the null
literal, to encourage using undefined
instead.
Why is this bad?
There are some reasons for using undefined
instead of null
.
- From experience, most developers use
null
andundefined
inconsistently and interchangeably, and few know when to use which. - Supporting both
null
andundefined
complicates input validation. - Using
null
makes TypeScript types more verbose:type A = {foo?: string | null}
vstype A = {foo?: string}
.
Example
Examples of incorrect code for this rule:
javascript
let foo = null;
Examples of correct code for this rule:
javascript
let foo;