Programming language/Reactjs

Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.

hello-world 2022. 7. 27. 12:27
728x90
반응형

CRA 로 리엑트 작업중에 interface 를 export 선언하자 아래와 같은 에러 발생.

Re-exporting a type when the '-isolatedModules' flag is provided requires using 'export type'.

우선 컴파일 옵션이 가물가물하여  --isolatedModules 을 찾아보았다.

--isolatedModules  :  추가 검사를 수행하여 별도의 컴파일 

(예를 들어 트랜스파일된 모듈 혹은 @babel/plugin-transform-typescript) 이 안전한지 확인합니다.

옵션  타입  기본값
--isolatedModules  boolean false

라고 한다..

그리고 TS 버전을 찾아보니 3.8 부터는 type-only imports exports를 위해 type 이란 것을 붙여야 한다고 한다.

 

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export

 

Documentation - TypeScript 3.8

TypeScript 3.8 Release Notes

www.typescriptlang.org

 

 

아래와 같이 선언되면 될 것 같다.

import React from 'react';

interface IRoute{
    path: string;
    element: React.ExoticComponent<React.ComponentPropsWithRef<()=> JSX.Element> >;
}

interface IRouteGroup extends IRoute{
    children?: IRoute[];
}

export type {
    IRoute,
    IRouteGroup
}

 

728x90
반응형