export const getRequiredValueByKey = ( key: KEY, map: Record, ): VALUE => { if (!map.hasOwnProperty(key)) { throw new Error(`getRequiredValueByKey(${key})`); } return map[key]; }; export const getValueByKey = ( key: KEY, map: { [key: string]: VALUE; }, defaultValue: VALUE, ): VALUE => { if (!map.hasOwnProperty(key)) { if (defaultValue) { return defaultValue; } throw new Error(`getValueByKey(${String(key)})`); } return map[key]; };