feat(i18n): added OtherLanguageWrapExhaustive for exhaustive other languages
This commit is contained in:
parent
d4040a768f
commit
bbd738f572
2 changed files with 19 additions and 2 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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: {
|
||||
|
|
Loading…
Reference in a new issue