import { MutableRefObject } from 'react'; import { MessageGroupForwardedRefContent } from '../components/MessageGroup'; type BuildMapToMessageSetterReturnType = { [MessageSetterID in keyof T]: MessageSetterFunction; }; const buildMapToMessageSetter = ( mapToID: T, messageGroupRef: MutableRefObject, ): BuildMapToMessageSetterReturnType => Object.entries(mapToID).reduce>( (previous, [key, id]) => { const setter: MessageSetterFunction = (message?) => { messageGroupRef.current.setMessage?.call(null, id, message); }; previous[key as keyof T] = setter; return previous; }, {} as BuildMapToMessageSetterReturnType, ); export default buildMapToMessageSetter;