如果内部模块之前有一个import语句,则它不起作用 [英] Internal Module does not work if it has an import statement before it
问题描述
我正在尝试从使用外部( export
)模块更改为使用内部模块。但是当我删除导出时出现错误。
I am trying to change from using external (export
) modules, to using internal modules. But I am getting an error when I remove the "export".
我有这样的文件:
box.ts:
import {computedFrom} from 'aurelia-framework';
module Entities {
export class Box { .. Stuff }
我在另一个文件中使用它。
I use this in another file.
service-actions.ts:
/// <reference path="../entities/box.ts" />
....
var box = new Entities.Box();
这给了我以下错误:
'typeof(实体)'上不存在属性'Box'
Property 'Box' does not exist on 'typeof(Entities)'
但如果我拿出从'aurelia-framework'导入{computedFrom};
然后错误消失(它工作正常)。
But if I take out import {computedFrom} from 'aurelia-framework';
then the error is gone (it works fine).
我尝试将 import {computedFrom}移动到模块中。当我这样做时,错误消失了,但我得到了一个新错误:
I tried moving the import {computedFrom} from 'aurelia-framework';
into the module. When I do that the error is gone, but I get a new one:
命名空间中的导入声明无法引用模块。
Import declarations in a namespace cannot reference a module.
我该怎么做才能使用 computedFrom
模块我的课? (它必须是一个外部模块才能工作吗?)
What can I do to be able to use the computedFrom
module in my class? (Does it have to be an external module for it to work?)
推荐答案
总的来说,它是最好避免混合内部和外部模块。
外部模块(或现在已知的模块)实际上相当优雅,您可以在没有内部模块(或名称空间)的情况下组织您的代码因为他们现在已经知道了。)
External modules (or modules as they are now known) are actually rather graceful, and you can organise your code really well without internal modules (or namespaces as they are now known).
box.ts:
import {computedFrom} from 'aurelia-framework';
export class Box { .. Stuff }
service- actions.ts:
import {Box} from './box'
var box = new Box();
这篇关于如果内部模块之前有一个import语句,则它不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!