문제는 typeScript에서는 현재 performance.getEntriesByType의 프로퍼티 "type" 값을 인식 못하고 아래와 같은 오류가 발생한다는 점이다.
Property 'type' does not exist on type 'PerformanceEntry'.
이는 entries type은 PerformanceEntry으로 인식되고 있지만 실제 entries에 담겨 있는 오브젝트는 PerformanceNavigationTiming이다. 때문에 현재 PerformanceEntry에서 포함되지 않은 필드값 type은 확인할 수 없어 위와 같은 타입에러 발생한다. 관련 오브젝트에 대한 내용은 아래 두 가지의 링크를 참고하자.
그러면 최종적으로는 어떻게 해야 할까? 이는 typescript의 Type Assertion를 사용하면 된다. 우리는 performance.getEntriesByType 가 명확히 PerformanceNavigationTiming 오브젝트를 리턴해 준다는 사실을 알고 있다. 때문에 entries 객체를 명시적으로 PerformanceNavigationTiming 타입으로 재정의 해주면 된다.
"const entriesNavigationTiming = entries as PerformanceNavigationTiming" 코드 한 줄을 추가해 주면 된다.