未定义导入的模块

时间:2017-08-17 20:31:11

标签: node.js typescript

学习nodejs + typescript,同时遇到这样的情况:

情况:

的folder1 / file1.ts

    export module ModuleFactory{
         export function do(){
              return new SomeClass();
         }
    }

文件夹2 / file2.ts

    import {ModelFactory} from "../folder1/file1";

    class Usage{
      constructor(){
          this.rez = ModelFactory.do();
      }
    }

问题是我得到rez未定义。在调试期间,我注意到ModelFactory抛出:ReferenceError: ModelFactory is not defined

问题出在哪里?

1 个答案:

答案 0 :(得分:1)

这样做:

<强>的folder1 / file1.ts

export function do(){
  return new SomeClass();
}

<强>文件夹2 / file2.ts

import * as ModuleFactory from '../folder1/file1';

class Usage{
  constructor(){
    this.rez = ModuleFactory.do();
  }
}