3 ms·
> Here’s a specific example, it’s a “maybe” function as it only returns the friends of a user, if the user is logged in. Basically it introduces a possible retu
by TYMorningCoffee 3y ago
> Here’s a specific example, it’s a “maybe” function as it only returns the friends of a user, if the user is logged in. Basically it introduces a possible return null.
function maybeGetUser(): User | null {
if (!loggedIn) {
return null;
}
return fetchUser();
}
I believe this is an error. The code sample I took from the article is about getting a user, not the user's friends.
Since that function will return a list, an empty List might work.