2017-01-03 71 views
2

我试图使用Ramda.js如下:进口R(ramda)为打字稿的.ts文件

/// <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; 

回答

4

您可以选择使用import语句导入它:

import * as R from "ramda"; 

而且,你不必使用/// <reference />了,只是做npm install --save @types/ramda

+0

当'--module'为'none'时,出现错误'无法使用导入,导出或模块增量。哪个模块选项会使我与我以前使用过的'/// '最接近? – Jim

+0

您可以在'tsconfig.json'中将'compilerOptions.module'设置为'commonjs'并使用'import'statements。 – Saravana