이제 catch 메서드가 붙을 때의 타입을 알아봅시다.

    const chaining = await Promise.resolve('hi')
      .then(() => {
        return 123;
      })
      .then(() => {
        return true;
      })
      .catch((err) => {
        console.error(err);
      });
    // const chaining: boolean | void
    export {};
    

    catch 메서드의 타입은 다음과 같습니다.

    lib.es5.d.ts

    interface Promise<T> {
      (...)
      catch<TResult = never>(
        onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null
      ): Promise<T | TResult>;
    }
    
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.