⁉️

TIL: type을 export할 때 TS1205: Cannot re-export a type when the '--isolatedModules' flag is provided.

Date
2021/03/08
Tags
TIL
Frontend
TypeScript
Created by

상황

CRA로 만든 앱에서 type만을 정의하고 export하는 entity 파일을 만드려 했는데 다음 에러가 발생했다.
TS1205: Cannot re-export a type when the '--isolatedModules' flag is provided.
Plain Text
복사
isolatedModules 플래그를 끄려고 tsconfig.json을 수정해도 CRA에서 자동으로 isolatedModules 플래그를 켜기 때문에 소용없었다.

Type-Only Imports and Export

TS 3.8부터는 type-only imports와 exports를 위해 새로운 문법이 추가되었다. 다음과 같이 쓸 수 있다.
import type { SomeThing } from "./some-module.js"; export type { SomeThing };
JavaScript
복사
따라서 type을 export하기 위해서는 위와 같이 type 키워드를 붙여주면 된다.

References