我在我的 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记录此弃用状态:
deprecate pipeable module, use the specific helpers instead
什么是“特定助手”?我该如何解决这个警告?
最佳答案
要解决此警告,请导入 pipe
来自 fp-ts/lib/function
而不是 fp-ts/lib/pipeable
:
import { pipe } from 'fp-ts/lib/function'
关于typescript - fp-ts - 不推荐使用管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67480062/