本文整理匯總了TypeScript中yup.MixedSchema.when方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript MixedSchema.when方法的具體用法?TypeScript MixedSchema.when怎麽用?TypeScript MixedSchema.when使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類yup.MixedSchema
的用法示例。
在下文中一共展示了MixedSchema.when方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
mixed.isType("hello");
mixed.strict(true);
mixed.strip(true);
mixed.withMutation(schema => {});
mixed.default({ number: 5 });
mixed.default(() => ({ number: 5 }));
mixed.default();
mixed.nullable(true);
mixed.required();
mixed.notRequired(); // $ExpectType MixedSchema
mixed.typeError("type error");
mixed.oneOf(["hello", "world"], "message");
mixed.notOneOf(["hello", "world"], "message");
mixed.when("isBig", {
is: value => true,
then: yup.number().min(5),
otherwise: yup.number().min(0)
});
mixed
.when("isBig", {
is: true,
then: yup.number().min(5),
otherwise: yup.number().min(0)
})
.when(
"$other",
(value: any, schema: MixedSchema) =>
value === 4 ? schema.required() : schema
);
// tslint:disable-next-line:no-invalid-template-strings
mixed.test("is-jimmy", "${path} is not Jimmy", value => value === "jimmy");
示例2:
mixed.cast({});
mixed.isType('hello');
mixed.strict(true);
mixed.strip(true);
mixed.withMutation(schema => {});
mixed.default({ number: 5});
mixed.default(() => ({ number: 5}));
mixed.default();
mixed.nullable(true);
mixed.required();
mixed.typeError('type error');
mixed.oneOf(['hello', 'world'], 'message');
mixed.notOneOf(['hello', 'world'], 'message');
mixed.when('isBig', {
is: value => true,
then: yup.number().min(5),
otherwise: yup.number().min(0)
});
mixed.when('isBig', {
is: true,
then: yup.number().min(5),
otherwise: yup.number().min(0)
}).when('$other', (value: any, schema: MixedSchema) => value === 4 ? schema.required() : schema);
// tslint:disable-next-line:no-invalid-template-strings
mixed.test('is-jimmy', '${path} is not Jimmy', value => value === 'jimmy');
mixed.test({
name: 'lessThan5',
exclusive: true,
// tslint:disable-next-line:no-invalid-template-strings
message: '${path} must be less than 5 characters',
test: value => value == null || value.length <= 5