Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
actraiser opened this issue Oct 16, 2018 · 1 comment
Closed

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

actraiser opened this issue Oct 16, 2018 · 1 comment

Comments

@actraiser
Copy link

actraiser commented Oct 16, 2018

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant