d.ts 파일?

·2022년 2월 2일

typescript용 definition, description이라 보면 된다.

이를 테면 기존에 js로 쓰던 어떤 메소드나 함수가 있다고 치자.
그걸 타입스크립트에서 '그대로' 가져다 쓰면 뭔가 이상하지 않을까?

우리가 직접 작성하는 함수나 클래스 같은 것들 작성할 땐 타입을 신경써서 작성하는데, 메소드는 쌩 js로 쓴다? 말이 안 된다.

d.ts는 그것들의 타입을 적어놓는 곳이다.

Promise를 예시로 보자.


interface Promise<T> {
    /**
     * Attaches callbacks for the resolution and/or rejection of the Promise.
     * @param onfulfilled The callback to execute when the Promise is resolved.
     * @param onrejected The callback to execute when the Promise is rejected.
     * @returns A Promise for the completion of which ever callback is executed.
     */
    then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;

    /**
     * Attaches a callback for only the rejection of the Promise.
     * @param onrejected The callback to execute when the Promise is rejected.
     * @returns A Promise for the completion of the callback.
     */
    catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<T | TResult>;
}
profile
모르는 것 투성이

0개의 댓글