最近我在一个打字稿项目的VSCode中遇到了以下情况:
档案:some-interface.ts
// no import statements have been skipped. This is the whole file:
export interface SomeInterface {
property: AnotherInterface;
}
和文件:another-interface.ts
:
export interface AnotherInterface {
// ...
}
好的 - 因为在some-interface.ts
VS代码中没有import语句向我显示了无法找到类型AnotherInterface
的错误。当然这是预期的行为。但是我很快意外地从export
中删除了another-interface.ts
关键字 - VS代码停止了抱怨并且可以正确地解决该类型。
那么有谁知道这里发生了什么?这是预期的行为,还是打字稿或vs代码的错误?
那么有谁知道这里发生了什么?这是预期的行为,还是打字稿或vs代码的错误?
这是预期的行为。如果文件中没有export
和import
,则它是脚本而不是模块。然后,在脚本中,所有成员都是全局成员。