【发布时间】:2023-02-09 23:33:45
【问题描述】:
假设我想将一组逻辑规则存储在一个对象中:
const rule1 : Rule = {
">" : [3,2]
}; // Which represents : 3>2
const rule2 : Rule = {
"and" : [
{ ">" : [3,1] },
{ "<" : [1,3] }
]
}; // Which represents : (3>1) && (1<3)
我这样写我的类型:
type Operand = number | string | Rule
type Operator =
"var" |
"===" |
"!==" |
"<=" |
"<" |
">=" |
">" |
"or" |
"and" ;
interface Rule extends Record<Operator, [Operand, Operand]> { }
但是我收到以下错误Type '{ ">": [number, number]; }' is missing the following properties from type 'Record<Operator, [Operand, Operand]>': var, "===", "!==", "<=", and 4 more.
我做错了什么?
【问题讨论】:
标签: typescript recursion types logic