feat(i18n): added OtherLanguageWrapExhaustive for exhaustive other languages

This commit is contained in:
teidesu 2022-09-12 15:34:30 +03:00
parent d4040a768f
commit bbd738f572
2 changed files with 19 additions and 2 deletions

View file

@ -68,3 +68,17 @@ export type OtherLanguageWrap<Strings> = {
? OtherLanguageWrap<Strings[key]>
: never
}
/**
* Wrapper type for i18n object containing strings for a language
* other than the primary one. Used to provide type safety.
*
* Unlike {@link OtherLanguageWrap}, this type requires all strings
* from the primary language to be present
*/
export type OtherLanguageWrapExhaustive<Strings> = {
[key in keyof Strings]: Strings[key] extends I18nValue<infer A>
? I18nValue<A>
: Strings[key] extends Record<string, any>
? OtherLanguageWrapExhaustive<Strings[key]>
: never
}

View file

@ -3,8 +3,11 @@
// This file is never executed, only compiled
import { Message } from '@mtcute/client'
import { createMtcuteI18n } from '../src'
import { OtherLanguageWrap } from '../src/types'
import {
createMtcuteI18n,
OtherLanguageWrapExhaustive,
OtherLanguageWrap,
} from '../src'
const en = {
basic: {