Let’s proceed with step 5
(5) Add safety to boolean expressions, and improve handling of
nullandundefined
- To catch problematic truthy/falsy expressions, enable the ESLint rule
@typescript-eslint/strict-boolean-expressions- Enable the tsconfig option
strictNullChecksto ensure that ifnullis desired to be an allowed value in a type, it has to be explicitly stated as such- Enable the tsconfig option
exactOptionalPropertyTypesto catch occurrences where optional properties are explicitly set to the valueundefinedinstead of being deleted
There are a few places where you’ll need to change if (!foo) to if (typeof foo === 'undefined'). Use care when deciding whether null should be handled specifically — it’s easy to make mistakes!
Fix compiler and lint errors until all of the important commands succeed
shyarn typecheckyarn lintyarn test
This is the last of the “tightening up strictness” steps we’ll complete together, because they all pretty much feel this way, and we have more interesting things to discuss.