Skip to content

Commit a08d67d

Browse files
authored
Merge pull request #66 from DouglasNeuroInformatics/fix-translator-namespace-type
fix: translator namespace type issue
2 parents 6800476 + f6f69f6 commit a08d67d

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/i18n/types.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1+
/* eslint-disable @typescript-eslint/no-empty-object-type */
12
/* eslint-disable @typescript-eslint/consistent-type-definitions */
23
/* eslint-disable @typescript-eslint/no-namespace */
34

45
import type { OmitIndexSignature, Primitive, Simplify } from 'type-fest';
56

67
import type libuiTranslations from './translations/libui.json';
78

9+
interface TranslationsLike {
10+
[key: string]: TranslationsLike | { [L in Language]?: string };
11+
}
12+
813
export declare namespace UserConfig {
914
interface LanguageOptions {
1015
[key: string]: boolean;
1116
}
12-
interface Translations {
13-
[key: string]:
14-
| Translations
15-
| {
16-
[L in Language]?: string;
17-
};
18-
}
17+
interface Translations extends TranslationsLike {}
1918
}
2019

2120
export type LanguageOptions = UserConfig.LanguageOptions & {
@@ -44,7 +43,7 @@ export type TranslationNamespace = Extract<keyof Translations, string>;
4443
export type TranslationKey = ExtractTranslationKey<Translations>;
4544

4645
export type TranslationKeyForNamespace<TNamespace extends TranslationNamespace> =
47-
TranslationKey extends `${TNamespace}.${infer TKey}` ? TKey : never;
46+
Extract<TranslationKey, `${TNamespace}.${string}`> extends `${TNamespace}.${infer TKey}` ? TKey : never;
4847

4948
export type TranslateFormatArgs =
5049
| Exclude<Primitive, symbol>[]

0 commit comments

Comments
 (0)