Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

javascript - 打字稿库:隐藏内部导出(Typescript library: Hide internal exports)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...