UNPKG

@plone/types

Version:

Plone's Types Package

38 lines (31 loc) 1.05 kB
/** * Map utility "type" to its method signature. * Extend via module augmentation: * declare module '@plone/types' { interface UtilityTypeMap { foo: (id: string) => string } } */ export interface UtilityTypeMap { validator: ValidatorUtility; transform: (data: any) => any; fieldFactoryInitialData: (intl: any) => Record<string, any>; fieldFactoryProperties: (intl: any) => Record<string, any>; } export type ValidatorUtilityArgs = { value: any; field: Record<string, any>; formData: any; formatMessage: (...args: any[]) => any; }; export type ValidatorUtility = ( options: ValidatorUtilityArgs, ) => string | null | undefined; type UtilityMethodFor<Type extends string> = Type extends keyof UtilityTypeMap ? UtilityTypeMap[Type] : (...args: any[]) => any; export type Utility<Type extends string = string> = Record< string, { method: UtilityMethodFor<Type> } >; type UtilitiesByMap = { [Type in keyof UtilityTypeMap]: Utility<Type>; }; export type UtilitiesConfig = UtilitiesByMap & Record<string, Utility>;