Typescript,需要模块作为类

Typescript, require module as class

本文关键字:模块 Typescript      更新时间:2024-06-30

我正在使用一个现有的js库,该库在我的typescript代码中使用AMD模块。我想使用Javascript类作为Typescript类的基础。这就是我要做的:

著名.js

define('famous/core/View',['require','exports','module'],function(require, exports, module) {
    function View() {
        ...
    }
    ...
    module.exports = View;
});

查看.d.ts

声明模块"著名/核心/视图"{

}

AppView.ts

import-View=require('amous/core/View');

类AppView扩展视图{

}

export=AppView;

但上面写着"找不到名字‘View’"。我认为它不起作用是合乎逻辑的,因为模块不是类,但我不知道其他方法。

您需要定义一个类并在View.d.ts中使用export =。例如:

declare module "famous/core/View" {
   class View {
      // TODO define members of View
   }
   export = View;
}

经过进一步分析,这似乎纯粹是一个需要配置的问题。它不应该与classmodule有任何关系。你确定你的路径是正确的,并且你有一个config.ts必需的配置文件吗?