0

I have a recurring problem that is caused by someone importing from a module that should only be used locally.

Imagine the following setup:

  • src/app/index.js -> imports from src/lib/i18n/index.js
  • src/lib/i18n/index.js -> imports from src/lib/i18n/text.js
  • src/lib/i18n/text.js

In the above example src/app/index.js is the main application entry point and src/lib/i18n/index.js contains the api for the i18n. The file src/app/index.js contains the public i18n API and itself imports from 'src/lib/i18n/text.js'.

I would now like to keep people from bypassing the actual i18n api defined in src/lib/i18n/index.js by directly accessing 'src/lib/i18n/text.js'.

Is there a way to do this in TypeScript?

doberkofler
  • 9,511
  • 18
  • 74
  • 126
  • 1
    To the best of my knowledge... no. I believe you can essentially make your files an external library though. Either through NPM or this technique https://stackoverflow.com/a/54772741/1626866 – BobtheMagicMoose Oct 06 '22 at 18:07

0 Answers0