typescript - typescript @types/yup 验证返回未定义?
问题描述
我在我的打字稿项目中使用 yup 已经有一段时间了。它需要 @types/yup 来定义类型。我正在使用v0.26.4
它,一切都很好。但是今天我将依赖项更新为v0.29.3
. 这里不对劲:
//The object schema constructor from
<T extends object>(fields?: ObjectSchemaDefinition<T>): ObjectSchema<T>;
//changed to
<T extends object>(fields?: ObjectSchemaDefinition<T>): ObjectSchema<T | undefined>;
//then for my validation code:
const validated = await CreateNewsValidator.validate(req.body); // T | undefined
//when i use validated, the error Type 'undefined' is not assignable to type X comes
我的问题是验证方法何时返回未定义?什么是解决方法,我应该切换回 0.26.4 吗?他们为什么要做出这样的改变?
解决方案
推荐阅读
- node.js - 无法使用 node.js 和 Angular.js 获取 Express 路由路径
- html - 如何修复“在移动设备中加载时无法加载图像”?
- c - 在遇到一定数量的换行符后,我的程序会返回我想要的正确位置吗?
- firebase - 收到来自 Firebase 云消息传递的通知,但它们未显示在云消息传递报告中
- sql-server - 关于 sp_executesql 的错误
- flutter - 有没有我可以使用的文件选择器。我尝试了一些,但他们没有工作
- python - 如何从列表中修复“TypeError:'str' object is not callable”
- docker - Docker 容器自动删除 - Bamboo
- java - 是否可以从 Map 制作 String[][]
使用流 API? - python - 如何在 PyCuda 中使用 tex2D?