0

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
1
  • It allows it because, as you know, you have --strictNullChecks disabled. Are you asking "why does disabling --strictNullChecks disable strict null checks"? That's answered below. Or are you asking "why is --strictNullChecks disabled by default"? That's probably answered here: it would break existing real world code that used TypeScript before these --strict options existed. Commented Oct 24, 2019 at 14:48

1 Answer 1

2

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),

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.