typescript - Ramda 的 LensProp 类型定义
问题描述
当使用 Ramda 的时候lensProp
喜欢:
R.lensProp('x')
我收到此错误:
Argument of type 'string' is not assignable to parameter of type 'never'.ts(2345)
解决方案
看起来您需要传入您希望lensProp
操作的类型,以便它知道使用时要返回的类型。您可以通过传入泛型参数来做到这一点。
这是与 typescript 配合得很好的文档中的修改示例:
import R from 'ramda'
interface Point {
x: number
y: number
}
const xLens = R.lensProp<Point>('x');
R.view(xLens, {x: 1, y: 2}); //=> 1
R.set(xLens, 4, {x: 1, y: 2}); //=> {x: 4, y: 2}
R.over(xLens, R.negate, {x: 1, y: 2}); //=> {x: -1, y: 2}
推荐阅读
- excel - 有没有办法使用 v 查找或具有重复查找但不同行值的不同公式?
- image - 使用 bolbs (php) 在数据库中插入和显示图像
- python - 如何使用 pytest 测试 numba 矢量化函数
- java - 单元测试无限重复通量
- firebase - 我可以从 Firestore 中的单个集合中检索多少个文档?
- javascript - 如何在反应时从另一个组件调用 onSubmit 事件?
- xaml - 如何在 Windows App SDK(WIN UI/Project Reunion)项目中自定义窗口标题栏?
- python - 如何在 pygame 中移动 Rect(使用 Rect.x、Rect.y)?
- android - 我在 com.codeavenge.calculator.MainActivity.updateTex 收到一些错误
- html - 大型 HTML 表格的最佳 css