HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
육개짱 프론트엔드
육개짱 프론트엔드
/
🚀
declare module은 다른 module을 import 할 수 없다…
🚀

declare module은 다른 module을 import 할 수 없다…

 
결론부터 말하자면
🚨
d.ts 파일의 타입들을 다른 d.ts 파일에서 import 할 수 없습니다.
 
  • TypeScript에서 declare module은 기존의 모듈을 확장하거나 새로운 모듈을 선언하는데 사용
  • declare module 구문은 파일의 최상위 수준에서만 사용할 수 있으며, 다른 import문과 함께 사용할 수 없습니다.
 
 
notion image
notion image
 
  • auth-models 모듈을 사용하던 기존 코드들이 전부 에러 발생
    • GPT 왈) d.ts끼리는 누가 먼저 선언되는지 알 수 없음
    • 따라서 서로 타입을 공유할 수 없음 (언제 선언될지 모르니까)
  • 즉, 하나의 module 에서 전부 선언하는 방법뿐임
 
// 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해서 사용중 } }