이때는 직접 타이핑하여 향후 모든 타입이 any가 되는 것을 방지해야 합니다.

    fetch('url').then<{ data: string }>((response) => {
      return response.json();
    }).then((result) => { 
    });
    // (parameter) result: { data: string;}
    
    const result: { hello: string } = JSON.parse('{"hello":"json"');
    

    <{ data: string }>은 제네릭이라는 문법으로 2.14절에서 배웁니다. 그리고 then 메서드에 타이핑한 것이 어떻게 다음 then 메서드에 영향을 미치는지는 3.10절에서 알아보겠습니다.

    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.