infer input extra params on defineStrategyComponent

This commit is contained in:
Georges KABBOUCHI 2021-09-06 01:32:36 +03:00
parent d2bca27ab6
commit 76461deca6

View File

@ -43,7 +43,7 @@ export enum StrategyComponentType {
HEADING = "heading", HEADING = "heading",
VALUE = "value", VALUE = "value",
STATUS = "status", STATUS = "status"
} }
export type StrategyComponentParameterMap = { export type StrategyComponentParameterMap = {
@ -62,12 +62,14 @@ export type StrategyComponentParameterMap = {
[StrategyComponentType.HEADING]: {}; [StrategyComponentType.HEADING]: {};
[StrategyComponentType.VALUE]: {}; [StrategyComponentType.VALUE]: {};
[StrategyComponentType.STATUS]: { [StrategyComponentType.STATUS]: {
liquidation?: any, liquidation?: any;
status?: any, status?: any;
}; };
}; };
export interface IStrategyComponent<ComponentType extends StrategyComponentType> { export interface IStrategyComponent<
ComponentType extends StrategyComponentType
> {
type: ComponentType; type: ComponentType;
name: string; name: string;
@ -75,19 +77,22 @@ export interface IStrategyComponent<ComponentType extends StrategyComponentType>
placeholder?: ( placeholder?: (
context: IStrategyContext & { context: IStrategyContext & {
component: IStrategyComponent<ComponentType> & StrategyComponentParameterMap[ComponentType]; component: IStrategyComponent<ComponentType> &
StrategyComponentParameterMap[ComponentType];
} }
) => string; ) => string;
validate?: ( validate?: (
context: IStrategyContext & { context: IStrategyContext & {
component: IStrategyComponent<ComponentType> & StrategyComponentParameterMap[ComponentType]; component: IStrategyComponent<ComponentType> &
StrategyComponentParameterMap[ComponentType];
} }
) => string | void; ) => string | void;
defaults?: (context: Omit<IStrategyContext, "components">) => object; defaults?: (context: Omit<IStrategyContext, "components">) => object;
update?: ( update?: (
context: IStrategyContext & { context: IStrategyContext & {
component: IStrategyComponent<ComponentType> & StrategyComponentParameterMap[ComponentType]; component: IStrategyComponent<ComponentType> &
StrategyComponentParameterMap[ComponentType];
} }
) => void; ) => void;
@ -122,10 +127,14 @@ export interface IStrategy {
submitText?: string; submitText?: string;
} }
export function defineStrategyComponent<ComponentType extends StrategyComponentType>( export function defineStrategyComponent<
component: IStrategyComponent<ComponentType> ComponentType extends StrategyComponentType
>(
component: IStrategyComponent<ComponentType> &
StrategyComponentParameterMap[ComponentType]
) { ) {
return component as IStrategyComponent<ComponentType>; return component as IStrategyComponent<ComponentType> &
StrategyComponentParameterMap[ComponentType];
} }
export function defineStrategy(strategy: IStrategy) { export function defineStrategy(strategy: IStrategy) {