I understand that NonNullable is meant to remove null and undefined as valid values for a type, but it seems it is not working as expected.
I have the following code:
interface User {
name: string;
}
type NonNullableUser = NonNullable<User>;
let user1 : NonNullable<User> = { name: "foo"}
let user2 : NonNullable<User> = null // expect this to lead to a type error
I expect let user2 : NonNullable<User> = null to not compile but it still does! Note, I set the
strictNullChecks to off, because if I set it to on, the compiler automatically prevents null assignment and let user2: User = null would lead to a compile error removing the need for the utility type NonNullable.
If I need to have strictNullChecks on for this work, then I wonder if NonNullable is not redundant then?
Or perhaps I do not get how to make use of NonNullable? Any thoughts?