I am building a library in typescript that is being published via npm.
(我正在使用正通过npm发布的打字稿建立一个库。)
In the index.ts, which is the starting point of the library, all the public classes and enums are exported.
(在作为库的起点的index.ts中,所有公共类和枚举都被导出。)
import { MyClass } from './internal/my-class'
import { MyEnum } from './internal/my-enum'
export { MyClass, MyEnum }
This works well, but I noticed that users are able to import internal functions/classes etc. as well by using a direct path to the file.
(这很好用,但是我注意到用户也可以通过使用文件的直接路径来导入内部函数/类等。)
// in a project that installed my library as an npm dependency
import { InternalClass } from 'my-lib/dist/internal/internal-class'
Is there a way to prevent this?
(有办法防止这种情况吗?)
I need to "export" InternalClass
because I'm importing and using it throughout my library, but I don't want to expose it publicly.
(我需要“导出” InternalClass
因为我正在整个库中导入和使用它,但是我不想公开地公开它。)
I tried using namespaces, but couldn't really get it to work.(我尝试使用名称空间,但无法真正使用它。)
ask by Andreas Gassmann translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…