const NUMBER_FORMAT_OPTIONS_ALIASES = [ // 'temperature', ] as const; export type NumberFormatAlias = (typeof NUMBER_FORMAT_OPTIONS_ALIASES)[number]; export const createNumberFormatOptionsFor = ( alias: NumberFormatAlias ): Intl.NumberFormatOptions => { if (!NUMBER_FORMAT_OPTIONS_ALIASES.includes(alias)) { const these = NUMBER_FORMAT_OPTIONS_ALIASES.join(', '); const message = `Unsupported alias "${alias}", we only support ${these}`; throw new Error(message); } let out: Intl.NumberFormatOptions = {}; const _real: Intl.NumberFormatOptions = {}; const createRequiredKeyProxyHandler = (keyPath: string) => () => new Error(`Mising argument for "${keyPath}" in NumberFormatOptions`); /** * OK, gotta research more than quick experiment * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy */ const handler: ProxyHandler = { get(target, prop, receiver) { }, }; switch (true) { case alias === 'temperature': { Object.assign(_real, { style: 'unit', unit: createRequiredKeyProxyHandler('unit'), }); out = new Proxy(out, handler); } break; } return out; };