Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a package with the isolatedModules=true option enabled?

In a file where I export all the classes of my package on lines like the following:

export {default as BoundList, IBoundListOption, TBoundListFilterFn} from './list/BoundList';

errors of the form are generated:

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

How do I export classes now?

This problem occurred in CRA2.1. There was forced to isolatedModules=true. I'm making a component library on CRA2.1

like image 300
Khusamov Sukhrob Avatar asked Nov 23 '18 09:11

Khusamov Sukhrob


1 Answers

CRA v3.4.1 facilitates type re-exports under --isolatedModules. The contained @babel/preset-typescript in version v7.9.0+ (see corresponding Babel release and announcement) and TypeScript support TS 3.8 type-only imports and exports. You can now write:

export type { MyListType } from "./list/BoundList"

// or
import type { MyListType } from "./list/BoundList"
export type { MyListType }
// note additional "type" keyword

Take a look at this answer for more info on the import/export syntax.

like image 189
ford04 Avatar answered Oct 12 '22 14:10

ford04