I have a function that should have a generic parameter, like this:
async function getAll<T>(model: Model<T>, limit = 10) {
....
}
So I decided to call this function using lodash curry:
const specificGetAll = curry(getAll)(model)
specificGetAll(10)
This results in a "This expression is not callable. Type '' has no call signatures."
Two questions arise from this:
Use
const specificGetAll = curry(getAll, 2)(model)
instead of
const specificGetAll = curry(getAll)(model)
As limit is an optional parameter in the getAll function, getAll.length is 1. Lodash wrongly thinks your function getAll has one argument, so curry returns a promise instead of a function.
As for your second question: currying is a commonly known and widely used programming technique. There should be not any difficulties for other programmers working on your code to understand it. However, depending on the library used, there may be occasional problems with the automatic generation of types for curried functions. In that case, be ready to add some types manually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With