- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设我有这个不可变列表:
type Friend = {
name: string,
phone: string
}
const aList: List<Friend> = List([...])
现在我有一个具有以下签名的函数,它应该使用 friend 的列表:
const doStuffs = (friends: Array<Friend>): any => {...}
我想将 aList 转换为数组来调用它,如下所示:
doStuffs(aList.toJS())
但是我有一个流程错误,aList.toJS()
不是Array<Friend>
是否可以输入检查aList.toJS()
的结果或者我是否必须像这样定义我的函数:
const doStuffs = (friends: Array<any>): any => {...}
最佳答案
如果您确定.toJS()
方法返回 Friend
的数组,使用typecast through any让流程知道。
例如
const arrOfFriends = ((aList.toJS(): any): Array<Friend>)
我知道有时使用 any
很糟糕,但是如果您确定将会出现什么情况并且您不想编写自己的 .toJS()
变体,那么它会很有用。
或者,您可以编写一个实际转换 List<Friend>
的方法。到Array<Friend>
。也许如果您想真正确定代码的正确性。就我个人而言,我只会选择 any
如上所述进行类型转换并编写几个单元测试。
关于javascript - ImmutableJS/FlowType : Is it possible to typeCheck an array returned by a List. toJS(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49917230/
我通过 TypeScript 和 Vite 创建了一个新的 Vue 项目 npm init vue@latest 在 package.json 文件中有一个 typecheck 脚本 "typeche
考虑以下(无效的)Agda 代码 data Example : Example ex → Set where ex : Example ex 这种类型可以通过以下方式在 Agda 中有效写入,利用
有人可以解释@TypeChecked 和@CompileStatic 之间的区别吗? 我用@TypeChecked 读到它不可能在运行时添加新方法。 哪些其他功能是不允许的? @CompileStat
我正在阅读 Monad Transformer文档。我遇到过这个代码示例: import qualified Data.Map as Map import Control.Monad.Identity
在 agda 文档中,我读到当“无法解决目标以外的某些元变量时,代码将以黄色突出显示” 我试图在一个有点退化的案例中理解这一点。 如果我定义一个常规产品类型,那么一个愚蠢的程序就可以正常工作。 dat
我正在关注this lecture作者:西蒙·佩顿·琼斯 (Simon Peyton-Jones) 关于 GADT 的文章。在那里,声明了以下数据类型: data T a where T0 ::
我正在使用 HHVM 编写一个系统工具,但我终究无法弄清楚为什么当我运行 hh_client 时这段代码会出错 $__al_paths = array(); function requires(str
我有一个宏注释,旨在应用于类定义。它的目的是一个几乎但不完全序列化的工具。它检查类的构造函数参数,然后在伴随对象上创建一个工厂方法,该方法反过来为参数提供值。它需要知道参数的类型才能做到这一点,所以我
我正在使用 typescript 库进行一些反射(reflection)。我主要使用 ts.createSourceFile 并传递存储在内存中的文件。这非常有效,我可以轻松地在节点之间移动,以将绑定
例子: const red = Symbol('red'); const green = Symbol('green'); type TColor2 = | typeof red | type
我开始使用 Scala 宏,它们很棒,但我遇到了类型化(又名类型检查)和非类型化 Tree 之间的区别s。 例如,您不能拨打 c.eval出于某种原因使用类型检查树。我在 scala 宏文档中找不到关
如何使用 Flow 对从 fromJS 生成的 Immutable.JS 数据结构的形状进行类型检查?可以使用对象字面量符号非常准确地键入普通的旧 JS blob: type ObjectShape
假设我有这个不可变列表: type Friend = { name: string, phone: string } const aList: List = List([...]) 现在我有一
我只看过standard tutorial并且摸索了一下,所以我可能会遗漏一些简单的东西。 如果这在 Idris 中是不可能的,请解释原因。此外,如果可以用另一种语言完成,请提供代码示例并解释使之成为
基于此Guide升级我的复杂项目后: 当我构建库时,我收到此错误: Building Angular Package -----------------------------------------
Groovy 2.3.2 和 IntelliJ IDEA 13.1.4 考虑以下示例: 1. @TypeChecked class ImmutabilityUtils { static Lis
部署到 EC2 CodeDeploy 时运行 npm install --only=product 失败并显示以下日志。 [stdout]> typechecker@2.0.8 preinstall
我正在尝试使用 CLI 通过 Ionic 和 React 创建一个项目。我注意到错误出现在 Typescript 检查步骤中。 我一直在尝试以下方法来解决它: 删除 node_modules 和 pa
我目前无法构建 hhvm,因为无法访问 64 位 VM,所以我无法使用他们拥有的类型检查器。他们的文档似乎没有详细描述类型检查器(hh_server 和 hh_client?)的操作。 我想知道的是,
问题在于以下错误, [错误] 在 scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:4580)[错误] 在 scal
我是一名优秀的程序员,十分优秀!