简体   繁体   English

如果内部模块前面有导入语句,则该模块不起作用

[英]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.

相关问题 导入语句在打字稿中不起作用 - Import statement does not work in typescript 此导入语句如何工作? - How does this import statement work? 为什么 JEST 不适用于 import 语句/NEXTJS? - Why JEST does not work with import statement / NEXTJS? 为什么模块级别的return语句在Node.js中有效? - Why does a module level return statement work in Node.js? 错误&#39;缺少声明&#39; - @import - Error Missing 'Before Statement' - @import 为什么它告诉我,在导入 ReactJs 时不能在模块外使用导入语句 - Why does it tell me that , Cannot use import statement outside a module while import ReactJs “不能在模块外使用 import 语句” - JavaScript 模块导入到 TypeScript 文件中,JavaScript 模块内有其他导入 - "Cannot use import statement outside of module" - JavaScript module imported into TypeScript file, JavaScript module has other imports within inheritance 模块外的导入语句 - inheritance import statement outside a module 当模块有导出时,Js 缩小不起作用 - Js minification does not work when module has exports 如何使 `import` 语句在使用 node:vm 模块创建的代码中正常工作? - How to make the `import` statement work properly inside the code created using the node:vm module?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM