0

I have an async function, that returns either a string(token) or false(if the user isn't logged in):

const isLoggedIn = async ()=>{
  const token = getToken();
  if(!token){
    return false;
  }
   const { data } = await axios({
    method: "get",
    url: `${rootUrl}/login/isLoggedIn`, //
    headers:{
      token
    }

  });
  if(data.content.isLoggedIn === 'true'){//
     return token;
  }else{
    clear();
    return false;
  }

}

I was wondering how to properly document the @return of the function. It should convey the fact that the promise can be resolved with either a string or a boolean, something like this:

* @returns {Promise:string|boolean}

Is there some convention regarding this? Should i even mention that the function returns a promise?

i.brod
  • 3,993
  • 11
  • 38
  • 74
  • 3
    It may make more sense to return just a single type. It looks like you're returning a token if the user is logged in, so it might be better if you rename the function to `fetchUserToken()` then you can say the return type if `Promise`. – c1moore Aug 02 '19 at 22:12
  • Or even reject the promise if the user isn't logged in. – AuxTaco Aug 02 '19 at 22:27

0 Answers0