我"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 模块,改用特定的助手
什么是“特定帮手”?我该如何解决这个警告?
要解决此警告,请导入pipe
fromfp-ts/lib/function
而不是fp-ts/lib/pipeable
:
import { pipe } from 'fp-ts/lib/function'
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1762 次 |
最近记录: |