Ramda 和 Typescript:添加缺失的类型
Ramda and Typescript: add missing typings
我在当前项目中使用 TypeScript 和 Ramdajs。而且我刚刚意识到遗漏了一些打字,即 innerJoin
函数没有打字(@types/ramda 版本是 0.25.36,我现在是最新的)。
我尝试在项目中的单独文件中添加自定义定义:
declare namespace R {
interface Static {
innerJoin(): any;
}
}
甚至:
declare let R: R.Static;
declare namespace R {
interface Static {
innerJoin(): any; /* here should be a specific signature */
}
}
export = R;
export as namespace R;
但没有成功 - 打字稿将 R.innerJoin(/*...*/)
标记为未知:
Property 'innerJoin' does not exist on type 'Static'
有人知道如何正确实施吗?
我找到了解决方法:const R_innerJoin = (R as any).innerJoin
但我怀疑应该有更优雅的解决方案使用 '.d.ts' ...
P.S。如果这很重要,ramda 版本是 0.25.0。
更新
我是这样使用 Ramda 的:
import * as R from 'ramda';
const myFn = (a, b) => R.innerJoin(// etc
由于您要从模块中导入 R
命名空间,因此您必须扩充原始模块。如果您声明自己的 R
命名空间,您充其量只会看到您的命名空间或导入的命名空间,而不是合并。经过一些试验和错误后,以下对我有用:
declare module "dummy" {
module "ramda" {
interface Static {
innerJoin(): any;
}
}
}
需要外部模块声明以使内部模块声明成为 "augmentation" 而不是隐藏原始模块,如 this thread 中所述。不幸的是,这个技巧没有正确记录 AFAIK。
我在当前项目中使用 TypeScript 和 Ramdajs。而且我刚刚意识到遗漏了一些打字,即 innerJoin
函数没有打字(@types/ramda 版本是 0.25.36,我现在是最新的)。
我尝试在项目中的单独文件中添加自定义定义:
declare namespace R {
interface Static {
innerJoin(): any;
}
}
甚至:
declare let R: R.Static;
declare namespace R {
interface Static {
innerJoin(): any; /* here should be a specific signature */
}
}
export = R;
export as namespace R;
但没有成功 - 打字稿将 R.innerJoin(/*...*/)
标记为未知:
Property 'innerJoin' does not exist on type 'Static'
有人知道如何正确实施吗?
我找到了解决方法:const R_innerJoin = (R as any).innerJoin
但我怀疑应该有更优雅的解决方案使用 '.d.ts' ...
P.S。如果这很重要,ramda 版本是 0.25.0。
更新
我是这样使用 Ramda 的:
import * as R from 'ramda';
const myFn = (a, b) => R.innerJoin(// etc
由于您要从模块中导入 R
命名空间,因此您必须扩充原始模块。如果您声明自己的 R
命名空间,您充其量只会看到您的命名空间或导入的命名空间,而不是合并。经过一些试验和错误后,以下对我有用:
declare module "dummy" {
module "ramda" {
interface Static {
innerJoin(): any;
}
}
}
需要外部模块声明以使内部模块声明成为 "augmentation" 而不是隐藏原始模块,如 this thread 中所述。不幸的是,这个技巧没有正确记录 AFAIK。