首页 > 解决方案 > 流程无法决定在联合类型上选择哪种情况

问题描述

当我尝试联合元组有一些长度的数组时,我得到了错误

看看这个工作示例,其中每种类型都有不同的长度。例子(UPD:将流程版本更改为 0.71)

但是当我尝试添加一些长度流的类型时无法解决它。例子

type Step<T> = T | [T] | [T, Object];

type S3 = [Step<'Z'>]
type S4 = [Step<'X'>]

type S = S3 | S4

let a6: S = ['Z']
let a7: S = [['Z']]

错误:

11: let a7: S = [['Z']]
            ^ Could not decide which case to select. Since case 1 [1] may work but if it 
doesn't case 2 [2] looks promising too. To fix add a type annotation to array literal [3].

References:
8: type S = S3 | S4
            ^ [1]
8: type S = S3 | S4
                 ^ [2]
11: let a7: S = [['Z']]
                ^ [3]

我怎么解决这个问题?

标签: javascriptflowtype

解决方案


推荐阅读