Dealing with type safety
I am trying to do something like this:
if (result.length === 0) {
throw new Error(
No user with id ${id} found.
);
}
return result[0];
But typescript complains that { .... } | undefined is assignable to { ... }. How could i fix that? Should the if already deal with the case in which result is undefined?1 Reply
You have to assign it to a variable first to make the TS compiler happy