선언 파일의 또 다른 중요한 기능은 모듈의 상태를 설명하는 기능입니다. 모듈의 문자열 이름
앞에
declare
키워드를 사용하면 모듈의 내용을 타입 시스템에 알릴 수 있습니다.
다음
"
my
-
example
-
lib
"
모듈은
modules
.
d
.
ts
선언 스크립트 파일에 존재하도록 선언한 다
음,
index
.
ts
파일에서 사용됩니다.
// modules.d.ts
declare module "my-example-lib" {
export const value: string;
}
// index.ts
import { value } from "my-example-lib";
console.log(value); // Ok
코드에서
declare
module
을 자주 사용해서는 안 됩니다.
declare
module
은 주로 다음 절에
나오는 와일드카드
wildcard
모듈 선언과 이 장의 후반부에서 다루는 패키지 타입과 함께 사용됩
니다. 또한 타입스크립트가
.
json
파일의 가져오기를 기본으로 인식하도록 설정하는 컴파일
러 옵션인
resolveJsonModule
에 대한 정보는
13
장 ‘구성 옵션’에서 확인할 수 있습니다.
11.4.1 11.4.1
와일드카드와일드카드
모듈모듈
선언선언
모듈 선언은 자바스크립트와 타입스크립트 파일 확장자가 아닌 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.