fp-ts - 管道已弃用
fp-ts - pipe is deprecated
我在我的 typescript/react 项目中使用 "fp-ts": "^2.10.5"
,但我收到一条警告,指出“pipe”已被弃用。下面的代码来自 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
什么是“特定帮手”?我该如何处理这个警告?
要解决此警告,请从 fp-ts/lib/function
而不是 fp-ts/lib/pipeable
:
导入 pipe
import { pipe } from 'fp-ts/lib/function'
我在我的 typescript/react 项目中使用 "fp-ts": "^2.10.5"
,但我收到一条警告,指出“pipe”已被弃用。下面的代码来自 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
什么是“特定帮手”?我该如何处理这个警告?
要解决此警告,请从 fp-ts/lib/function
而不是 fp-ts/lib/pipeable
:
pipe
import { pipe } from 'fp-ts/lib/function'