[yup] Added better definition for yup's SchemaDescription.fields (#40822)

* Added better definitions for SchemaDescription.fields

* indentation fix
This commit is contained in:
Adam Kuśmierz
2020-02-05 17:43:34 +01:00
committed by GitHub
parent cf05cab21b
commit 141c76f567
2 changed files with 43 additions and 2 deletions

18
types/yup/index.d.ts vendored
View File

@@ -351,12 +351,28 @@ export interface TestOptions<P extends Record<string, any> = {}, R = any> {
exclusive?: boolean;
}
export interface SchemaFieldRefDescription {
type: 'ref';
key: string;
}
export interface SchemaFieldInnerTypeDescription extends Pick<
SchemaDescription, Exclude<keyof SchemaDescription, 'fields'>
> {
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<string, SchemaFieldDescription>;
}
// ValidationError works a lot more like a class vs. a constructor

View File

@@ -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 = {