【问题标题】:fp-ts - pipe is deprecatedfp-ts - 不推荐使用管道
【发布时间】: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


【解决方案1】:

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

import { pipe } from 'fp-ts/lib/function'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-18
    • 1970-01-01
    • 2019-02-28
    • 2021-10-29
    • 1970-01-01
    • 1970-01-01
    • 2021-08-24
    • 2021-08-28
    相关资源
    最近更新 更多