【问题标题】:Unable to refer external module in TypeScript无法在 TypeScript 中引用外部模块
【发布时间】:2015-08-17 01:13:38
【问题描述】:

我想在我的TypeScript 代码中使用一个外部模块,但它失败了。具体来说,我想在我的 TypeScript 脚本中使用引用 external.d.ts 文件中的方法。

我的代码是:

module test {

    //This is not working. I want to know the syntax to refer to express here.
    private express: typeof express = require("express");

    export testserver
    {
        constructor(private app:express.Application)
        {
          //Can not find express symbol
        }
    }

【问题讨论】:

  • “失败”是什么意思?

标签: module typescript external


【解决方案1】:
//This is not working. I want to know the syntax to refer to express here.
private express: typeof express = require("express");

使用import:

  import express = require("express");

  export testserver
  {
       constructor(private app:express.Application)
       {
       }
  }

并且不要混合内部和外部模块。 YouTube 视频中有更多内容TypeScript Modules Demystified: Internal, AMD with RequireJS, CommonJS with Node.js

【讨论】:

    【解决方案2】:

    这也适用于

     import * as express from 'express';
    

    但问题是有时我在编译时得到空白的 javascript 文件。这是一个已知问题吗?我是打字稿的新手,如果有任何问题请纠正我。谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-27
      • 2015-08-11
      • 1970-01-01
      • 2014-04-05
      • 2014-09-27
      • 1970-01-01
      相关资源
      最近更新 更多