我正在使用 Ramda.js 和 Typescript。为了从对象中获取一些值,我使用lensPath。
例子:
export interface Store {
foo: {
bar: string;
};
}
const store: Store = {
foo: {
bar: 'baz'
}
};
const fooBarLens = R.lensPath(['foo', 'bar']);
不幸的是,如果我将通过我的 WebStorm 进行一些重构并将属性重命名bar为bazin class Store,那么函数fooBarLens将停止工作。
但是如果在重构之前我会重写这个函数fooBarLens,比如:
const fooBarLens = (s) => s.foo.bar;
然后重构将正常工作。
如何在lensPath不硬编码属性名称的情况下重写 using 和其他 Ramda 函数并避免重构问题?