[英]Internal Module does not work if it has an import statement before it
I am trying to change from using external ( export
) modules, to using internal modules. 我正在尝试从使用外部(
export
)模块更改为使用内部模块。 But I am getting an error when I remove the "export". 但是,删除“导出”时出现错误。
I have a file like this: 我有一个像这样的文件:
box.ts: box.ts:
import {computedFrom} from 'aurelia-framework';
module Entities {
export class Box { .. Stuff }
I use this in another file. 我在另一个文件中使用它。
service-actions.ts: service-actions.ts:
/// <reference path="../entities/box.ts" />
....
var box = new Entities.Box();
This gives me the following error: 这给了我以下错误:
Property 'Box' does not exist on 'typeof(Entities)'
属性“ Box”在“ typeof(Entities)”上不存在
But if I take out import {computedFrom} from 'aurelia-framework';
但是,如果我
import {computedFrom} from 'aurelia-framework';
then the error is gone (it works fine). 然后错误消失了(工作正常)。
I tried moving the import {computedFrom} from 'aurelia-framework';
我尝试将
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.
名称空间中的导入声明不能引用模块。
What can I do to be able to use the computedFrom
module in my class? 我该怎么做才能在我的班级中使用
computedFrom
模块? (Does it have to be an external module for it to work?) (它必须是外部模块才能正常工作吗?)
On the whole, it is best to avoid mixing internal and external modules . 总体而言,最好避免将内部和外部模块混合使用 。
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: box.ts:
import {computedFrom} from 'aurelia-framework';
export class Box { .. Stuff }
service-actions.ts: service-actions.ts:
import {Box} from './box'
var box = new Box();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.