【发布时间】:2019-06-24 23:40:54
【问题描述】:
我有下一个类型定义:
type $Schema = {
type?: 'object' | 'string' | 'number' | 'array',
properties?: { [key: string]: $Schema },
additionalProperties?: boolean,
range?: [number, number],
required?: Array<string>
}
我想更改它以防止将尚未在 properties 中定义的密钥放入 required。
在下一个例子中,使用xx 应该被标记为错误,因为它在'properties'中定义:
{
required: ['id', 'xx'],
properties: { id: { type: 'string' } }
}
更难的例子:
const testSchema = {
properties: {
foo: {
type: 'object',
properties: {
bar: {
type: 'string'
}
},
required: ['buz']
}
},
required: ['foo']
}
我想让在流兼容的 IDE/编辑器中使用 JSON-Schema 时更难出错。
有可能吗?
【问题讨论】:
标签: javascript node.js flowtype