为什么Typescript定义文件不能保护成员?

Mat*_*ork 0 typescript

如果我将其另存为,则此代码无法编译test.ts.这是预期的,因为它cantSeeMe是隐藏的(export如果我想在模块外面看到它,我需要它.

但是,如果我保存文件,因为test.d.ts它编译正常.我也希望它不会编译.

为什么Typescript在编译为定义文件时不遵循相同的封装规则?

module blah {
  interface cantSeeMe { a: any; }
}

var variable: blah.cantSeeMe;
Run Code Online (Sandbox Code Playgroud)

Rya*_*ugh 5

export定义文件中的关键字是可选的,因为.d.ts文件的整个点是描述您的公共表面区域.