Add required fields to CrudActions type (#33809)
This commit is contained in:
parent
18a4b802ed
commit
385fa1e3f9
|
@ -23,24 +23,34 @@ export type ItemQuery = BaseQueryParams & {
|
|||
[ 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<
|
||||
{
|
||||
create: ( query: ItemQuery ) => Item;
|
||||
update: ( query: ItemQuery ) => Item;
|
||||
delete: ( id: IdType ) => Item;
|
||||
},
|
||||
ResourceName,
|
||||
MutableProperties,
|
||||
IdType,
|
||||
Generator< unknown, ItemType >
|
||||
> &
|
||||
MapActions<
|
||||
{
|
||||
delete: ( id: IdType ) => Item;
|
||||
},
|
||||
ResourceName,
|
||||
IdType,
|
||||
Generator< unknown, ItemType >
|
||||
>;
|
||||
>;
|
||||
|
||||
export type CrudSelectors<
|
||||
ResourceName,
|
||||
|
|
|
@ -26,14 +26,13 @@ type Query = BaseQueryParams< keyof ProductShippingClass > & {
|
|||
|
||||
type ReadOnlyProperties = 'id';
|
||||
|
||||
type MutableProperties = Partial<
|
||||
Omit< ProductShippingClass, ReadOnlyProperties >
|
||||
>;
|
||||
type MutableProperties = Omit< ProductShippingClass, ReadOnlyProperties >;
|
||||
|
||||
type ProductShippingClassActions = CrudActions<
|
||||
'ProductShippingClass',
|
||||
ProductShippingClass,
|
||||
MutableProperties
|
||||
MutableProperties,
|
||||
'name'
|
||||
>;
|
||||
|
||||
export type ProductShippingClassSelectors = CrudSelectors<
|
||||
|
|
Loading…
Reference in New Issue