Is there a way to tell TypeScript, that a certain type is no longer nullable if a certain call has been made in the code before?
So for example I have a call to an API and afterwards I know that the data is defined. But this call is happening somewhere at the outer shell of the application code, so when used later on, the data is already fetched.
More concretely I am fetching data with redux thunk and afterwards the data is stored in redux. But my selectors are all saying that the return type could be possibly undefined. Of course I could just type my Selectors to return the non nullable type but then I would need to be careful of where I am using the selectors.
Is there any elegant way or feature of TypesScript that could solve this problem better than defining multiple types of selectors? What are your approaches to this common problem?