Skip to content

[TS] Cannot re-export a type when the --isolatedModules flag is provided #6054

Closed
@ChristianIvicevic

Description

@ChristianIvicevic

Is this a bug report?

No

Description

Previously I used the following file structure for components:

FooComponent/
|- FooComponent.module.scss
|- FooComponent.tsx
|- index.tsx

In my FooComponent.tsx I'd basically define the following:

export interface IFooComponentProps { /* ... */ }
export function FooComponent(props: IFooComponentProps) { /* ... */ }

Furthermore I'd re-export the types in index.tsx as follows:

export { FooComponent, IFooComponentProps } from "./FooComponent";

Unfortunately CRA does not allow me to disable isolatedModules in the tsconfig.json and the compiler is complaining about re-exporting IFooComponentProps. In my use case I have an IFooComponentProps[] in another file that I am using to dynamically create FooComponents. It seems I have to move my props interface into separate files (especially when I use stateful components) which is just unnecessarily increasing the amount of files.

I'd like to know why CRA is enforcing isolatedModules (even automatically writing it to the config if I remove it manually) and how I may fix my design.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions