Back to Type Challenges

README.Zh CN

questions/00017-hard-currying-1/README.zh-CN.md

latest2.7 KB
Original Source
<!--info-header-start--><h1>柯里化 1 </h1><blockquote><p>by Anthony Fu <a href="https://github.com/antfu" target="_blank">@antfu</a></p></blockquote><p><a href="https://tsch.js.org/17/play/zh-CN" target="_blank"></a> &nbsp;&nbsp;&nbsp;<a href="./README.md" target="_blank"></a> <a href="./README.ja.md" target="_blank"></a> </p><!--info-header-end-->

在此挑战中建议使用TypeScript 4.0

柯里化 是一种将带有多个参数的函数转换为每个带有一个参数的函数序列的技术。

例如:

ts
const add = (a: number, b: number) => a + b
const three = add(1, 2)

const curriedAdd = Currying(add)
const five = curriedAdd(2)(3)

传递给 Currying 的函数可能有多个参数,您需要正确输入它的类型。

在此挑战中,柯里化后的函数每次仅接受一个参数。接受完所有参数后,它应返回其结果。

<!--info-footer-start-->

<a href="../../README.zh-CN.md" target="_blank"></a> <a href="https://tsch.js.org/17/answer/zh-CN" target="_blank"></a> <a href="https://tsch.js.org/17/solutions" target="_blank"></a> <hr><h3>相关挑战</h3><a href="https://github.com/type-challenges/type-challenges/blob/main/questions/00014-easy-first/README.zh-CN.md" target="_blank"></a> <a href="https://github.com/type-challenges/type-challenges/blob/main/questions/00016-medium-pop/README.zh-CN.md" target="_blank"></a> <a href="https://github.com/type-challenges/type-challenges/blob/main/questions/00462-extreme-currying-2/README.zh-CN.md" target="_blank"></a> <!--info-footer-end-->