'Typescript not showing that an object is nullable

I am having an issue with typescript where types with | null does not show as nullable. You can see the example below where I have the type

type A = {
    b: {
        c: number;
        d: string;
    } | null;
};

and then when I hover over b it does not show that it is nullable, and indeed when i use the type other places, it does not tell me that it could possibly be null

enter image description here

Does anyone know how to solve this?



Solution 1:[1]

Please enable strictNullChecks in your tsconfig.

You can use "strict":"true" too enable most of strict rules. The more strict rules are active - more safer your application is.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 captain-yossarian from Ukraine