From 8ed0a49ffd495dacdaa3acea90034e0c2d5d1896 Mon Sep 17 00:00:00 2001 From: Moreton Bay RC Date: Wed, 31 Jan 2018 10:34:21 +1000 Subject: [PATCH] Add examples for schema tests --- types/yup/yup-tests.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/types/yup/yup-tests.ts b/types/yup/yup-tests.ts index e23a6859ea..0fa05ac47d 100644 --- a/types/yup/yup-tests.ts +++ b/types/yup/yup-tests.ts @@ -261,3 +261,41 @@ setLocale({ number: { max: "Max message", min: "Min message" }, string: { email: "String message"} }); + +interface MyInterface { + stringField: string; + numberField: number; + subFields: SubInterface; +} + +interface SubInterface { + testField: string; +} + +const typedSchema = yup.object().shape({ + stringField: yup.string().required(), + numberField: yup.number().required(), + subFields: yup.object().shape({ + testField: yup.string().required(), + }).required(), +}); + +const testObject = { + stringField: "test1", + numberField: 123, + subFields: { + testField: "test2" + }, +}; + +typedSchema.validate(testObject); + +const untypedSchema = yup.object().shape({ + stringField: yup.string().required(), + numberField: yup.number().required(), + subFields: yup.object().shape({ + testField: yup.string().required(), + }).required(), +}); + +untypedSchema.validate(testObject);