如何解决如何扩展JavaScript中的函数以添加新类型?
我有一个扩展的PureFunction类,如下所示:
/**
* @class
* Represents a pure function.
* A pure function must have referential transparency.
* Which means for the same input it always gives the same output.
*/
export default class PureFunction extends Function {
constructor() {
super()
}
}
当我在下面的示例中使用上面的类时,它在注释中给出警告:
/**
* @template T
* @param v {T} A value
* @param f {PureFunction} Mapper function
* @return {T}
*/
const map = (v,f) => f(v) // Method expression is not of Function type
map(2,x => x ** 2) // Argument type function(any): any is not assignable to parameter type PureFunction
我该如何解决这个问题?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。