import R (ramda) into typescript .ts file

泪湿孤枕 提交于 2019-12-22 08:47:53

问题


I am attempting to use Ramda.js as follows:

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

I get error, Cannot find name 'R'

In the case of the ramda/index.d.ts file, the declaration (with detail omitted) is as follows:

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

export = R;

回答1:


You have to import it using the import statement:

import * as R from "ramda";

Also, you don't have to use /// <reference /> anymore, just do npm install --save @types/ramda.



来源:https://stackoverflow.com/questions/41441999/import-r-ramda-into-typescript-ts-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!