【发布时间】:2021-08-01 10:12:04
【问题描述】:
我在我的 typescript/react 项目中使用 "fp-ts": "^2.10.5",但我收到一条警告说“管道”已被弃用。以下代码来自this 使用 fp-ts 进行错误处理和验证的教程:
import { Either, left, right } from 'fp-ts/lib/Either'
import { chain } from 'fp-ts/lib/Either'
import { pipe } from 'fp-ts/lib/pipeable'
//
const minLength = (s: string): Either<string, string> =>
s.length >= 6 ? right(s) : left('at least 6 characters')
const oneCapital = (s: string): Either<string, string> =>
/[A-Z]/g.test(s) ? right(s) : left('at least one capital letter')
const oneNumber = (s: string): Either<string, string> =>
/[0-9]/g.test(s) ? right(s) : left('at least one number')
const validatePassword = (s: string): Either<string, string> =>
pipe(
minLength(s),
chain(oneCapital),
chain(oneNumber)
)
changelog 记录了此弃用状态:
弃用 pipeable 模块,改用特定的帮助器
什么是“特定助手”?我该如何解决这个警告?
【问题讨论】:
-
fp-ts/pipeable模块用于创建对管道友好的函数版本(请参阅旧版本的Option示例:github.com/gcanti/fp-ts/blob/…),由于 tree-shakeability 的原因,它已被弃用,如果我没记错的话。pipe刚刚从该模块移至fp-ts/function。
标签: typescript fp-ts