gpt4 book ai didi

javascript - 为什么 JS 传播运算符不能与 Flow 精确类型一起使用

转载 作者:行者123 更新时间:2023-11-30 14:39:53 24 4
gpt4 key购买 nike

当我使用Flow定义一个类型,然后使用展开运算符处理它时,为什么传入的参数是A类型,输出是A类型(修改后的值为a),Flow会认为是不精确匹配A 的属性)。

例如,这失败了:

type A = {|
attrib1: string,
attrib2: string
|};

const processA = (a: A) : A => {
return {...a, attrib2: 'hello' };
}

最佳答案

这是一个长期存在的错误,但只是(8 天前)得到了一些提交!

参见 https://github.com/facebook/flow/issues/2405

问题可以简化为:

/* @flow */
type A = {| a: string |}
const a: A = {a: 'x'}
const r: A = {...a}

在 master 上尝试这个现在可以工作,但不是 0.69.0

关于javascript - 为什么 JS 传播运算符不能与 Flow 精确类型一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49831176/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com