-
Notifications
You must be signed in to change notification settings - Fork 0
dict
hhh edited this page Dec 16, 2022
·
1 revision
/**
* 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>;