From 141c76f567ce0b7bf3cdc4cb66275f63ef1b0bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Ku=C5=9Bmierz?= Date: Wed, 5 Feb 2020 17:43:34 +0100 Subject: [PATCH] [yup] Added better definition for yup's SchemaDescription.fields (#40822) * Added better definitions for SchemaDescription.fields * indentation fix --- types/yup/index.d.ts | 18 +++++++++++++++++- types/yup/yup-tests.ts | 27 ++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/types/yup/index.d.ts b/types/yup/index.d.ts index aabeb3443e..b2939d050f 100644 --- a/types/yup/index.d.ts +++ b/types/yup/index.d.ts @@ -351,12 +351,28 @@ export interface TestOptions

= {}, R = any> { exclusive?: boolean; } +export interface SchemaFieldRefDescription { + type: 'ref'; + key: string; +} + +export interface SchemaFieldInnerTypeDescription extends Pick< + SchemaDescription, Exclude +> { + innerType?: SchemaFieldDescription; +} + +export type SchemaFieldDescription = + | SchemaDescription + | SchemaFieldRefDescription + | SchemaFieldInnerTypeDescription; + export interface SchemaDescription { type: string; label: string; meta: object; tests: Array<{ name: string; params: object }>; - fields: object; + fields: Record; } // ValidationError works a lot more like a class vs. a constructor diff --git a/types/yup/yup-tests.ts b/types/yup/yup-tests.ts index f1b2898749..af6fa3fd83 100644 --- a/types/yup/yup-tests.ts +++ b/types/yup/yup-tests.ts @@ -449,7 +449,32 @@ const description: SchemaDescription = { { name: 'test1', params: {} }, { name: 'test2', params: {} }, ], - fields: { key: 'value' }, + fields: { + refField: { + type: 'ref', + key: 'value', + }, + noSubField: { + type: 'type', + label: 'label', + meta: { key: 'value' }, + tests: [], + }, + subField: { + type: 'type', + label: 'label', + meta: { key: 'value' }, + tests: [], + fields: { key: { type: 'ref', key: 'value' } } + }, + withInnerType: { + type: 'type', + label: 'label', + meta: { key: 'value' }, + tests: [], + innerType: { type: 'ref', key: 'value' } + }, + }, }; const testOptions: TestOptions = {