[Typescript] interface or type name check

Darcy Daeseok YU ·2023년 7월 6일
0

자바스크립트에서 오브젝트의 타입 또는 인터페이스 네임 찾는 방법

interface Dog {
  bark: () => void;
}

  function isDog(pet: object): pet is Dog {
    return 'bark' in pet;
  }
  
  
  
  <div>
       {`${isDog({ a: 'aa' })}`}
       {`${isDog({ bark: () => {} })}`}
  </div>
profile
React, React-Native https://darcyu83.netlify.app/

0개의 댓글