I am learning typescript and I see a few counter-intuitive practices when it comes to null
and undefined
.
const a: null[] = null;
const b: null[] = [null];
const c: null[] = undefined;
const d: null[] = [undefined];
All the above statements do not cause any errors upon compiling. Although looking at it, it seems like it should be causing type errors. I have a feeling this has to do something with my understanding of null
and undefined
, but can someone please explain why this does not cause any errors and runs perfectly?
I thought it has something to do with not including "strict": true
in tsconfig.json
, but it seems to work even after including it.