diegohaz / arc

React starter kit based on Atomic Design
https://arc.js.org
2.91k stars 295 forks source link

Looking for a Typescript version of components/index.js #353

Closed actraiser closed 5 years ago

actraiser commented 5 years ago

Hi there,

my project is based on Typescript and I adopted lots of patterns from the arc-project like the convenient import of components. It works fine using the original .js version of components/index.js but for consistency plus keeping the build chain typescript-centric I would like to convert those few lines of code to TS as well which is actually harder than expected.

I am actually not able to figure out how to properly export the following code as a typescript module.

const req = require.context('.', true, /\.\/[^/]+\/[^/]+\/index\.tsx?$/);

req.keys().forEach((key) => {
  const componentName = key.replace(/^.+\/([^/]+)\/index\.tsx?/, '$1');
  module.exports[componentName] = req(key).default;
});

Whatever I try I get TS2306: File '/app/src/components/index.ts' is not a module

Has anyone migrated to Typescript and knows how to properly export the dynamically created module.exports-object?

Thanks -act

actraiser commented 5 years ago

Never mind - I switched to manual importing each component from their respective source path as using the method via require.context introduced a range of other problems (see #131 ).

So, since I am not using components/index.js anymore, there is no need for a TS-Version.

-act