Is it possible to compose a type which represents a tuple that returns either an error or the value?
async function createUser(userData): Promise<Either<User, UserError>> {}
// This should return a tuple where we have either an user or an error. Not both, not none
const [ user, userError ] = await createUser({ ... })
// Checking if there is an error
if (userError) {
...
// This line represents an early bail, could be throw or return
throw userError
}
// Since we check the error above, this should now be safe to use
console.log(user.name)