[英]Conditional chaining in JavaScript or TypeScript
Is there a syntax to add a function to a chain under conditions?是否有在条件下将 function 添加到链中的语法?
In this example, I would like myKey
to be Joi.string().required()
if modifier === true
, but just Joi.string()
if it is false
:在此示例中,如果
modifier === true
,我希望myKey
为Joi.string().required()
,但如果为false
则仅为Joi.string()
:
function customJoi(modifier) {
return Joi.object({
myKey: Joi.string() //#If(modifier) .required() #EndIf
});
}
I know I could do without this feature, with multiple steps.我知道我可以不使用此功能,但需要多个步骤。 I'm just wondering if there is a nice way to write it concisely for large objects.
我只是想知道是否有一种很好的方法可以为大型对象简洁地编写它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.