是否可以使用Flow中的最后一项重复定义元组?在Flow中定义无界元组
例子:
type Operator = '=' | '<' | '>';
type Value = string | number;
// this works...
type Expression = [Operator, Array<Value>];
const expr = ['=', [1, 2, 3]];
// ...but I would like to use it without nested array:
type Expression = [Operator, ...Value]; // this is not valid
const expr = ['=', 1, 2, 3];
流量不进行类型检查的基础上,指数的元组中的项目,因此可以将其定义是这样的:
type Expression = [Operator, Value, Value, Value, Value, Value];
const expr = ['=', 1, 2, 3];
但它不会进行类型检查的项目,如果该数组比类型定义长。
是的,即使对于同一个操作员,值的数量也可能有所不同。例如。逻辑运算符AND和OR: ['AND',['<','age',100],['=','country','Canada'],['>','foo',200] ] – dkl