mirror of
https://github.com/vercel/commerce.git
synced 2025-06-17 20:51:21 +00:00
15 lines
493 B
TypeScript
15 lines
493 B
TypeScript
import MissingConfigurationValueError from '../errors/MissingConfigurationValueError';
|
|
import type { NonUndefined, ValueOf } from '../types';
|
|
|
|
const requireConfig = <T>(isomorphicConfig: T, key: keyof T) => {
|
|
const valueUnderKey = isomorphicConfig[key];
|
|
|
|
if (typeof valueUnderKey === 'undefined') {
|
|
throw new MissingConfigurationValueError(`Value for configuration key ${key} was undefined.`);
|
|
}
|
|
|
|
return valueUnderKey as NonUndefined<ValueOf<T>>;
|
|
};
|
|
|
|
export default requireConfig;
|