CNA + ts로 미니 프로젝트를 진행하던 중, interface로 타입을 지정한 파일들을 폴더별로 나눠 저장한 후, 해당 파일들 안에서 export {} 를 해줬다.
그런데, 이후 컴파일을 해보니 다음과 같은 에러 메세지가 떴다.
"Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'."
에러 메세지를 해석해보면 "isolatedModules 플래그가 제공될 경우, type을 다시 내보려면 'export type'을 사용해야 한다."고 되어있다. 그래서 나는 아래 방법으로 문제를 해결했다.
1) export type
TS 버전을 찾아보면 3.8 버전부터 type-only imports와 exports를 위해 type 이란 것을 붙여야 한다고 나와있다. 그래서 type, interface는 import, export시에 type을 명시해준다.
interface PersonType {
name: string, age: number
}
interface AnimialType {
type: string, age: number
}
// 타입이 지정된 type, interface 는 export 시에 type이라고 명시
export type {
PersonType,
AnimialType
}
2) isolatedModules 속성 false로 변경
-isolatedModules : 추가 검사를 수행하여 별도의 컴파일
isolatedModules 속성에서 문제가 발생한듯하여, ts.config 파일을 살펴보니 해당 속성은 "true"로 지정되어 있었다.
해당 속성에 대해 찾아본 내용은 아래와 같다.
최종적으로 "false"로 바꾼 후 다시 컴파일 해보니 에러가 사라진 것을 확인할 수 있었다.