결론부터 말하자면
d.ts 파일의 타입들을 다른 d.ts 파일에서
import
할 수 없습니다.- TypeScript에서
declare module
은 기존의 모듈을 확장하거나 새로운 모듈을 선언하는데 사용
declare module
구문은 파일의 최상위 수준에서만 사용할 수 있으며, 다른 import문과 함께 사용할 수 없습니다.
// auth.d.ts import { UserSummary } from "api-models" // ⇒ 정상적으로 import 되는 것처럼 보였으나... declare module "auth-models" { export type emailAuthPayload = { accessToken: string } export type emailAuthResponseType = UserSummary export type emailRefreshPayload = { refreshToken: string } export type emailRefreshResponseType = { accessToken: string } export type emailLoginPayload = { email: string password: string } export type emailLoginResponseType = { accessToken: string refreshToken: string user: UserSummary // UserSummary를 import해서 사용중 } }


auth-models
모듈을 사용하던 기존 코드들이 전부 에러 발생- GPT 왈)
d.ts
끼리는 누가 먼저 선언되는지 알 수 없음 - 따라서 서로 타입을 공유할 수 없음 (언제 선언될지 모르니까)
- 즉, 하나의 module 에서 전부 선언하는 방법뿐임