我如何在Ramda中重写对象道具的类型检查

问题描述

我正在尝试着用Ramda重写以下TS代码:

const uniqueIdentifierRegEx = /.*id.*|.*name.*|.*key.*/i;
const uniqueIdentifierPropTypes = ['string','number','bigint'];

const findUniqueProp = (obj: any) => Object.keys(obj)
    .filter(prop => uniqueIdentifierPropTypes.includes(typeof obj[prop]))
    .find(prop => uniqueIdentifierRegEx.test(prop));

我最终得到了这样的东西,但它实际上没有用:

const data = {a:1,name: 'name',nameFn: () => {}};
const uniqueIdentifierRegEx = /.*id.*|.*name.*|.*key.*/i;
const uniqueIdentifierPropTypes = ['string','bigint'];

const filterPred = curry((obj,prop_,types) => includes(type(prop(prop_,obj)),types));
const findProd = curry((prop_,regEx) => regEx.test(prop))

const findUniqueProp = (obj,types,regEx) =>
   pipe(
     keys,filter(filterPred(types)),find(findProd(regEx))
   )(obj)

findUniqueProp(data,uniqueIdentifierPropTypes,uniqueIdentifierRegEx)

可能pickBy可以用来过滤道具……但是我迷路了。请帮助连接点。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)