object.values_流Object.values(…)

object.values

JavaScript typing utilities, like Flow and TypeScript, have become popular in JavaScript apps of all sizes. As I mentioned in our Script & Style Show typing podcast, typing is a great way to implicitly implement documentation and validation. Flow isn't always easy to perfect, however, and Object.values was a pain point for me.

JavaScript键入实用程序(例如Flow和TypeScript)已在各种规模JavaScript应用程序中流行。 正如我在Script&Style Show键入播客中所提到的那样,键入是隐式实现文档和验证的好方法。 Flow并不总是那么容易完美,但是Object.values对我来说是一个痛点。

When using Flow, Object.values could trigger the following error:

使用Flow时, Object.values可能触发以下错误:

Cannot call Object.values(…).map with function bound to callbackfn because property {prop} is missing in mixed [1] in the first argument.

无法使用绑定到callbackfn的函数来调用Object.values(…).map,因为在第一个参数的混合[1]中缺少属性{prop}。

The reason for this error is that Object.values() could return any value type. One way to get past this annoyance is to use the following:

出现此错误的原因是Object.values()可以返回任何值类型。 克服这种烦恼的一种方法是使用以下方法:

...(Object.values(whatever): any)

Using an any type is never ideal but providing a type with Object.values will help satisfy Flow. In the end, it does make sense that Object.values isn't trusted, because anything could be returned, but having to use any is a tough pill to swallow for type lovers!

使用any类型都不是理想的选择,但是为类型提供Object.values将有助于满足Flow。 最后,不信任Object.values是有道理的,因为可以返回任何内容,但是必须使用any很难使类型爱好者吞咽!

翻译自: https://davidwalsh.name/flow-object-values

object.values

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值