-
Notifications
You must be signed in to change notification settings - Fork 0
Exact return types for fields and members return value #11
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
To define the schema, currently we have to define types for nested elements so that extra fields would error. But, this approach gets a bit more verbose.
type FormSchema = ObjectSchema<PartialForm<FormType>>;
type FormSchemaFields = ReturnType<FormSchema['fields']>;
type MetaType = NonNullable<FormType['meta']>;
type MetaSchema = ObjectSchema<PartialForm<MetaType>>;
type MetaSchemaFields = ReturnType<MetaSchema['fields']>;
type CollectionType = NonNullable<NonNullable<FormType['collections']>>[number];
type CollectionSchema = ObjectSchema<PartialForm<CollectionType>>;
type CollectionSchemaFields = ReturnType<CollectionSchema['fields']>;
type CollectionsSchema = ArraySchema<PartialForm<CollectionType>>;
type CollectionsSchemaMember = ReturnType<CollectionsSchema['member']>;
const schema: FormSchema = {
fields: (): FormSchemaFields => ({
name: [requiredStringCondition],
meta: ({
fields: (): MetaSchemaFields => ({
age: [requiredCondition, greaterThanCondition(12)],
job: [],
}),
}),
collections: {
keySelector: (col) => col.clientId,
member: (): CollectionsSchemaMember => ({
fields: (): CollectionSchemaFields => ({
clientId: [],
date: [],
title: [requiredStringCondition],
}),
}),
},
}),
};Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request