使用最新的https://github.com/gcanti/io-ts/,我想建模 to 的属性result
包含NodeLsStatusResponse
类型NodeStatus
或NodeStatus404
in (t.readonlyArray)
如何定义这种关系io-ts?
export const Connection = t.union([t.literal('a'), t.literal('b')])
export type Connection = t.TypeOf<typeof Connection>
export const NodeStatus = t.type({
connection: Connection,
nodeId: t.string,
})
export const NodeStatus404 = t.type({
connection: Connection,
host: t.string,
})
export type NodeStatus = t.TypeOf<typeof NodeStatus>
export type NodeStatus404 = t.TypeOf<typeof NodeStatus404>
export const NodeLsStatusResponse = t.type({
code: t.literal('OK'),
result: t.readonlyArray(NodeStatus), /// <<< I would like to have a mixed array here
})