When using Ramda's lensProp
like:
R.lensProp('x')
I'm getting this error:
Argument of type 'string' is not assignable to parameter of type 'never'.ts(2345)
When using Ramda's lensProp
like:
R.lensProp('x')
I'm getting this error:
Argument of type 'string' is not assignable to parameter of type 'never'.ts(2345)
It looks you need to pass in the type that you expect the lensProp
to operate on, so that it knows what type to return when used. You can do that by passing in the generic parameter.
Here's the modified example from the docs that plays nice with 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}