Currently, I am leveraging redux sagas to fetch data asynchronously from various endpoints using a unified interface:
export interface ResponseInfo {
data?: any;
status: number;
headers?: any;
subCode?: string;
}
To ensure that null checking is enforced on the dynamic 'data' object (of type any), I require that every developer includes null checking when accessing properties. For example:
if(response.data.pizza.toppings){}
This code should result in a compile error unless proper null checks are added like so:
if(response.data && response.data.pizza && response.data.pizza.toppings){
}
While TypeScript with --strictNullChecks
does not catch the lack of null checking in the aforementioned line, I wonder if tslint's no-unsafe-any rule could address this issue. Is there a built-in way for TypeScript to perform this validation independently?