I just recently started refactoring my large scale angular app to Typescript's strict mode. Dealing with lots of null checks the question arose again if I should prefer using
null or vice versa. A couple of thoughts:
- Is using
undefinedfor initially undefined values and using
nullwhenever you want to unassign a value a good option?
undefinedeverywhere simplifies things at first, but then there is JSON (only
nullavailable) and API responses. How to best deal with those?
- How to best deal with pre-checks for when you are reasonably confident that a value is not
null, but it theoretically could be (e.g. angular
@Inputsyou always assign)? Do you prefer to typecast or do you use error checks?
I wonder how do you deal with the problem. Do you prefer one over the other? Do you use both? What's your take on it?