How to assert non-null with data fetching
How would you assert the profile.value to be non null?
The best senario would be to use a middleware to check if the user is loggedin and redirect them to the login page if they are not. The problem I'm facing is that the editor doesn't know that the user won't get on the page if the user is not logged in.
3 Replies
either put it in
else
, asser it via profile.value!
or similar
as TS does not know that the code will stop after navigateTo and you can't early return in script setupyou can also put it in a function and return early there, then call it (inline composable) - example
Alexander Lichter
YouTube
Organize your Composition API code (2k subscriber special)
✨ The Composition API is amazing - but organizing code is still a challenge sometimes, especially for all the people that were (or are) used to the Options API. In this video I point out common mistakes when organizing code and an easy way to avoid spaghetti code in Vue components with a bit more functionality
Key points:
✔ Building a Demo Appl...
Thanks, will look into these options!