Skip to content
hhh edited this page Dec 16, 2022 · 1 revision

dict

/**
 * Type of dictionaries.
 */
type Dict = Record<string | symbol, string>;

/**
 * Type of dictionary names.
 */
type DictName = string | symbol;

/**
 * Type of translations.
 */
type Translations<DictType extends Dict = Dict, DictNameType extends DictName = DictName> = Record<keyof DictType, Record<DictNameType, string>>;

/**
 * Create dicts from translations.
 *
 * @example
 * ```js
 * const dicts = translationsToDicts({
 *     HELLO: {
 *         en: 'hello',
 *         zh: '你好',
 *     },
 *     WORLD: {
 *         en: 'world',
 *         zh: '世界',
 *     },
 * });
 * ```
 */
const translationsToDicts: <DictType extends Dict = Dict, DictNameType extends DictName = DictName>(translations: Translations<DictType, DictNameType>) => Record<DictNameType, DictType>;
Clone this wiki locally