I probably need to rethink the way we structure our React components. We are using the latest react-scripts that allow Typescript to be used and by default, the isolatedModules
is being enabled which currently bugs me a bit.
We used to structure a component like this:
Component
|_ Component.tsx
|_ index.ts
|_ types.ts
Component.tsx
holds the actual component without declarationsindex.ts
is just re-exporting everything so we can have a singular entry point and can do something likeimport Component, { ComponentType } from '@/Component';
types.ts
holds the actual type definitions and exports most or all of them.
So far so good and that works without the isolatedModules
. However, we also export some of the type definitions, effectively re-exporting the interfaces that were specified within Component/types.ts
. This won't work as TypeScript itself would not transpile the code any longer.
How can I re-export this without having a separate import statement going to @/Component/types
(which might be actual the simpler way anyway)?