Internal Module does not work if it has an import

2020-05-04 04:42发布

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".

I have a file like this:

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();

This gives me the following error:

Property 'Box' does not exist on 'typeof(Entities)'

But if I take out import {computedFrom} from 'aurelia-framework'; then the error is gone (it works fine).

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.

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?)

1条回答
相关推荐>>
2楼-- · 2020-05-04 05:31

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:

import {computedFrom} from 'aurelia-framework';

export class Box  { .. Stuff }

service-actions.ts:

import {Box} from './box'

var box = new Box();
查看更多
登录 后发表回答