在Typescript中,为什么内部模块不能引用外部模块?

时间:2013-10-22 18:51:24

标签: compiler-construction typescript

出于好奇,我想知道:为什么在Typescript中编译器不允许这样的事情?是否存在安全隐患?它会导致语法问题吗?

export import Bar = require('./Path/To/Bar'); // this is allowed

module Foo {
    export import Bar = require('./Path/To/Bar'); // this is not allowed
}

目前,这会导致以下错误:

Import declarations in an internal module cannot reference an external module.

1 个答案:

答案 0 :(得分:1)

All features start at -100。原则上,编译器可以通过检查RHS来区分外部模块导入和内部模块导入,但实际上绝大多数外部模块导入都希望无论如何都要处于顶层,然后我们必须要计算当一个模块没有导出它的导入时,从可见性角度看它意味着什么(对于AMD来说,它甚至不清楚是否有任何意义)。

相关问题