打字稿:省略'export'关键字似乎使界面全局化?

jla*_*ang 4 typescript visual-studio-code

最近我在一个打字稿项目的VSCode中遇到了以下情况:

文件: some-interface.ts

// no import statements have been skipped. This is the whole file:
export interface SomeInterface {
    property: AnotherInterface;         
}
Run Code Online (Sandbox Code Playgroud)

和文件another-interface.ts::

export interface AnotherInterface {
    // ...
}
Run Code Online (Sandbox Code Playgroud)

好的 - 由于some-interface.tsVS代码中没有import语句,因此向我显示了AnotherInterface无法找到该类型的错误.当然这是预期的行为.但是,一旦我意外地删除了export关键字another-interface.ts- VS代码停止抱怨并且可以正确解决该类型.

那么有谁知道这里发生了什么?这是预期的行为,还是打字稿或vs代码的错误?

我用Google搜索,但在那里找不到提示.提前致谢!:)

Pal*_*leo 5

那么有谁知道这里发生了什么?这是预期的行为,还是打字稿或vs代码的错误?

这是预期的行为.如果文件中export既没有import,则它是脚本而不是模块.然后,在脚本中,所有成员都是全局成员.

另请参阅:Javascript中的经典脚本v/s模块脚本