Add required fields to CrudActions type (#33809)

This commit is contained in:
louwie17 2022-07-12 11:27:17 -03:00 committed by GitHub
parent 18a4b802ed
commit 385fa1e3f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 17 deletions

View File

@ -23,24 +23,34 @@ export type ItemQuery = BaseQueryParams & {
[ key: string ]: unknown; [ key: string ]: unknown;
}; };
export type CrudActions< ResourceName, ItemType, MutableProperties > = type WithRequiredProperty< Type, Key extends keyof Type > = Type & {
[ Property in Key ]-?: Type[ Property ];
};
export type CrudActions<
ResourceName,
ItemType,
MutableProperties,
RequiredFields extends keyof MutableProperties | undefined = undefined
> = MapActions<
{
create: ( query: Partial< ItemType > ) => Item;
update: ( query: Partial< ItemType > ) => Item;
},
ResourceName,
RequiredFields extends keyof MutableProperties
? WithRequiredProperty< Partial< MutableProperties >, RequiredFields >
: Partial< MutableProperties >,
Generator< unknown, ItemType >
> &
MapActions< MapActions<
{ {
create: ( query: ItemQuery ) => Item; delete: ( id: IdType ) => Item;
update: ( query: ItemQuery ) => Item;
}, },
ResourceName, ResourceName,
MutableProperties, IdType,
Generator< unknown, ItemType > Generator< unknown, ItemType >
> & >;
MapActions<
{
delete: ( id: IdType ) => Item;
},
ResourceName,
IdType,
Generator< unknown, ItemType >
>;
export type CrudSelectors< export type CrudSelectors<
ResourceName, ResourceName,

View File

@ -26,14 +26,13 @@ type Query = BaseQueryParams< keyof ProductShippingClass > & {
type ReadOnlyProperties = 'id'; type ReadOnlyProperties = 'id';
type MutableProperties = Partial< type MutableProperties = Omit< ProductShippingClass, ReadOnlyProperties >;
Omit< ProductShippingClass, ReadOnlyProperties >
>;
type ProductShippingClassActions = CrudActions< type ProductShippingClassActions = CrudActions<
'ProductShippingClass', 'ProductShippingClass',
ProductShippingClass, ProductShippingClass,
MutableProperties MutableProperties,
'name'
>; >;
export type ProductShippingClassSelectors = CrudSelectors< export type ProductShippingClassSelectors = CrudSelectors<