fp-ts - 管道已弃用

ANi*_*120 3 typescript fp-ts

"fp-ts": "^2.10.5"在我的打字稿/反应项目中使用,并且收到一条警告,称“管道”已被弃用。下面的代码来自教程,介绍如何使用 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)
  )
Run Code Online (Sandbox Code Playgroud)

记录此弃用的变更日志指出:

弃用 Pipeable 模块,改用特定的助手

什么是“特定帮手”?我该如何解决这个警告?

ANi*_*120 7

要解决此警告,请导入pipefromfp-ts/lib/function而不是fp-ts/lib/pipeable

import { pipe } from 'fp-ts/lib/function'
Run Code Online (Sandbox Code Playgroud)