원숭이가 Date
클래스에 패치하는 cached-date
이라는 NPM 패키지를 작성했습니다. 표준 문자열 표현을 캐시합니다.기본 제공 노드 클래스에 대한 외부 원숭이 패치를 선언합니다
// Typescript application
require('cached-date');
const date = new Date();
const isoStr = date.toCachedISOString();
:
이
// index.d.ts
declare interface Date {
toCachedString(): string;
toCachedDateString(): string;
toCachedISOString(): string;
toCachedJSON(): string;
toCachedTimeString(): string;
toCachedUTCString(): string;
}
다음 코드는 컴파일러 오류 Property 'toCachedISOString' does not exist on type 'Date'
을 산출 :
모든 것은 내가 유형의 정의가 패키지에 포함 된 인식 내 타이프 라이터 프로젝트를 얻을 수없는 것을 제외하고, 좋은 작품 다음
package.json
의 중요한 부분이다
// package.json
"main": "index.js",
"types": "index.d.ts",
,745,
궁금한 점은 index.d.ts
을 내 프로젝트의 로컬 선언 폴더 ("paths"
: tsconfig.json
)로 이동하고 변경하지 않고 모두 Date.d.ts
이라고 할 때 모든 것이 잘 수행됩니다.
// application
export interface Date {
toCachedString(): string;
toCachedDateString(): string;
toCachedISOString(): string;
toCachedJSON(): string;
toCachedTimeString(): string;
toCachedUTCString(): string;
}
나 외부 내장의 유형 선언을 병합하기위한 특별한 방법이 있나요 : 나는 응용 프로그램에서 다음과 같은 선언을 넣을 때
마찬가지로, 모두가 잘? 감사!