title: Axios & Typescript promise rejection error has type unkown
body: <p>The problem I'm currently facing is that I can't use a returned error from a promise rejection because it is not typeable with Typescript. For example when a signup request fails because the username is already taken I return a <code>400</code> with the <code>message</code> <code>username already taken</code>. But I can't access the message from the error because the <code>error</code> object from a <code>try catch</code> can't be typed.<br />
  Is there any way axios can handle this situation and can give me access to the error obejct with a custom type?<br />
  Or should I just create an error object under the data and either return it as <code>null</code> when the server has a <code>200</code> or return an error obejct?</p>
  <p>Example:</p>
  <pre class="lang-js prettyprint-override"><code>export interface ErrorRes {
    statusCode: number;
    error: string;
    message: string;
  }
  
  export interface ISignupRes {
    token: string;
    user: IUser;
    message: string;
  }
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>const handleSignUp = async () =&gt; {
    setLoading(true)
    try {
      const { data, status }: { data: ISignupRes; status: number } =
        await coreApi.post('/auth/signup', {
          email,
          username,
          firstname,
          lastname,
          password,
        })
      if (status === 200) {
        Storage.save(true, 'token', data.token)
        addNotification({
          type: 'success',
          message: data.message,
        })
      } else {
        // this never get's called because if the response returns an error it get's catched
        addNotification({
          type: 'error',
          message: data.message,
        })
      }
      setLoading(false)
    } catch (error) {
      // the error is of type `unkown` to I can't access `error.message`
      setLoading(false)
      addNotification({
        type: 'error',
        message: error.message,
      })
    }
  }
  </code></pre>