Reputation: 787
Why Typescript allows to pass null
/ undefined
there?
// "strictNullChecks": false
function someFun(param: (foo: any) => any) {}
someFun(null); // no error - incorrect
someFun(undefined); // no error - incorrect
Upvotes: 0
Views: 55
Reputation: 5132
Quoting from the docs
In strict null checking mode, the null and undefined values are not in the domain of every type and are only assignable to themselves and any (the one exception being that undefined is also assignable to void)
..T and T | undefined are considered synonymous in regular type checking mode (because undefined is considered a subtype of any T),
Upvotes: 2