當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript MixedSchema.test方法代碼示例

本文整理匯總了TypeScript中yup.MixedSchema.test方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript MixedSchema.test方法的具體用法?TypeScript MixedSchema.test怎麽用?TypeScript MixedSchema.test使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yup.MixedSchema的用法示例。


在下文中一共展示了MixedSchema.test方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: ExtendsMixed

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
});

yup.string().transform(function(this, value: any, originalvalue: any) {
    return this.isType(value) && value !== null ? value.toUpperCase() : value;
});

// Extending Schema Types
class ExtendsMixed extends yup.mixed {}
mixed = new ExtendsMixed();
開發者ID:Dru89,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:yup-tests.ts

示例2:

    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(
    "is-jimmy",
    ({ path, value }) => `${path} has an error, it is ${value}`,
    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
});
mixed.test(
    "with-promise",
    "It contains invalid value",
開發者ID:j-f1,項目名稱:forked-DefinitelyTyped,代碼行數:31,代碼來源:yup-tests.ts

示例3: Promise

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');
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
});
mixed.test('with-promise', 'It contains invalid value', value => new Promise(resolve => true));
const testContext = function(this: TestContext) {
    // $ExpectType string
    this.path;
    // $ExpectType ValidateOptions
    this.options;
    // $ExpectType any
    this.parent;
開發者ID:VincentDamour,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:yup-tests.ts


注:本文中的yup.MixedSchema.test方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。