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;
|
[ 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,
|
||||||
|
|
|
@ -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<
|
||||||
|
|
Loading…
Reference in New Issue