[TS] TypeScript exercises 12

Chobby·2023년 3월 23일
1

TS

목록 보기
6/6

해당 문제는 외부 라이브러리를 재정의 하는 문제로, 다양한 라이브러리 중 공통점이 있는 부분을 같은 타입으로 선언할 수 있는가를 물어보는 문제이다.

declare module 'stats' {
    type Comparator<T> = (a: T, b: T) => number

    type GetIndex = <T>(input: T[], comparator: Comparator<T>) => number
    export const getMaxIndex: GetIndex
    export const getMinIndex: GetIndex
    export const getMedianIndex: GetIndex

    type GetElement = <T>(input: T[], comparator: Comparator<T>) => T | null
    export const getMaxElement: GetElement
    export const getMinElement: GetElement
    export const getMedianElement: GetElement

    export const getAverageValue: <T>(input: T[], getValue: (item: T) => number) => number | null
}

index.d.ts를 위와같이 재정의하여 풀이할 수 있다.

profile
내 지식을 공유할 수 있는 대담함

0개의 댓글