【问题标题】:import R (ramda) into typescript .ts file将 R (ramda) 导入 typescript .ts 文件
【发布时间】:2017-01-03 11:01:45
【问题描述】:

我正在尝试按如下方式使用 Ramda.js:

/// <reference path="../../../node_modules/@types/ramda/index.d.ts" />
module App {
    var settab = R.once((element) => current(element));  
    function current(li: any) {
        // ...
    }    
}

我收到错误,找不到名称“R”

以ramda/index.d.ts文件为例,声明(略)如下:

declare var R: R.Static;    
declare namespace R {
    type Ord = number | string | boolean;
    interface Static {
        // .........
    }
}

export = R;

【问题讨论】:

    标签: javascript typescript ramda.js


    【解决方案1】:

    您必须使用import 语句导入它:

    import * as R from "ramda";
    

    另外,您不必再使用/// &lt;reference /&gt;,只需使用npm install --save @types/ramda。

    【讨论】:

    • 当 '--module' 为 'none' 时,我收到错误消息“无法使用导入、导出或模块扩充”。哪个模块选项可以让我最接近我以前使用 /// &lt;reference /&gt; 时所拥有的?
    • 您可以在tsconfig.json 中将compilerOptions.module 设置为commonjs 并使用importstatements。
    猜你喜欢
    • 2015-08-12
    • 1970-01-01
    • 2016-06-11
    • 1970-01-01
    • 2019-06-22
    • 2020-04-03
    • 1970-01-01
    • 2018-01-04
    • 1970-01-01
    相关资源
    最近更新 更多