typescript - fp-ts - 不推荐使用管道

标签 typescript fp-ts

我在我的 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/

相关文章:

javascript - 是否值得在 CMS 中使用 TypeScript?

javascript - 如何将 JS 字符串数组转换为与 io-ts 的联合?

typescript - 从对象中获取可选的通用值

typescript - fp-ts 和 Jest : ergonomic tests for Option and Either?

typescript :如何 kleisli compose (monadic compose) Promise monad using fp-ts

javascript - Typescript:在 Visual Studio 2013 中编译为多个 .js 文件

angularjs - 如何使用带有 Angular 依赖注入(inject)的 typescript 继承

visual-studio - 创建键盘快捷键以在同名的 html 和 typescript 文件之间切换

javascript - 在 Node/MongoDb 中创建架构

javascript - 使用 fp-ts 删除 Either 数组中的重复项