适用于 JS 和 TypeScript 的类型安全错误
Result 类型,用于表示成功( Ok )或失败( Err )。 对于异步任务, neverthrow 提供了 ResultAsync 类,它封装了 Promise<Result<T, E>>,并为您提供与普通 Result<T, E> 相同的表达能力和控制。 ResultAsync 具有 thenable 特性,这意味着它 完全像原生的 Promise<Result> 一样工作 ... 除了您可以访问 Result 提供的相同方法,而无需 await 或 .then 该 promise! 请查看 wiki 以了解示例和最佳实践。需要了解如何利用此套件进行错误处理的实际示例吗?请查看此仓库:https://github.com/parlez-vous/server
eslint-plugin-neverthrowResult)okerrResult.isOk()(方法)Result.isErr()(方法)Result.map()(方法)Result.mapErr()(方法)Result.unwrapOr()(方法)Result.andThen()(方法)Result.asyncAndThen()(方法)Result.orElse()(方法)Result.match()(方法)Result.asyncMap()(方法)Result.andTee()(方法)Result.orTee()(方法)Result.andThrough()(方法)Result.asyncAndThrough()(方法)Result.fromThrowable()(静态类方法)Result.combine()(静态类方法)Result.combineWithAllErrors()(静态类方法)](如果使用区分性的只读属性,则不需要 isOk()/isErr() 方法
维护状态
asyncAndThrough 在 Ok/Err 中实现,但缺少 IResult 接口
ResultAsync 缺少 _unsafeUnwrap() 和 _unsafeUnwrapErr() 测试工具
[建议] 为 Result 和 ResultAsync 使用 Do + bind / let
isErr() + 早退限制
使用循环
Result.combine() 与 Result<void, E>[] 的类型为 Result<void[], E>, 而这种明确类型与 @TypeScript-eslint/no-invalid-void-type 不兼容
早期返回/短路模式
在文档中提及 `safeTry` 错误推理限制