在Typescript中使用名称空间是惯用的吗?

我正在发布具有一些功能的库。其中一个函数返回库中的内部数据结构以用于调试。目前,我的类型声明文件如下所示:

export default function doSomething): void;
export function __dumpInternalRepresentation(): IR;

interface IR { ... }
interface Foo extends IR { ... }
interface Bar extends IR { ... }

However, I think this will be confusing to users because they will then be able to import IR, Foo, and Bar even though most people shouldn't import those.

因此,我正在考虑将声明文件切换为:

export default function doSomething): void;
export function __dumpInternalRepresentation(): internal.IR;

export namespace internal {
    export interface IR { ... }
    export interface Foo extends IR { ... }
    export interface Bar extends IR { ... }
}

This way, all the internal data structures are hidden inside of internal.

但是,我读到不建议将Typescript名称空间用于较新的代码。如果是这种情况,我该怎么办?

评论