From 9900542fc1ef48657ff3b5285b7dd0ea4eb4b727 Mon Sep 17 00:00:00 2001 From: eliyya Date: Fri, 20 Dec 2024 20:21:47 -0600 Subject: [PATCH] fix autocomplete --- src/index.ts | 13 +++++++++++-- src/keys.ts | 2 +- t.ts | 5 ----- 3 files changed, 12 insertions(+), 8 deletions(-) delete mode 100644 t.ts diff --git a/src/index.ts b/src/index.ts index 84d376b..a859107 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,19 @@ import i18n from 'i18n' import { LocaleKeys } from './keys.js' +type NestedKeyOf = { + [K in keyof T]: T[K] extends string + ? T[K] + : `${K & string}.${NestedKeyOf}` +}[keyof T] + interface Translate { - (phrase: K, options?: T[K]): string + >( + phrase: K, + options?: Record, + ): string } -// TODO: Fix the type of the phrase parameter + export function Translator(locale: string) { const translate: Translate = (phrase, options) => { return i18n.__mf({ phrase: phrase as string, locale }, options) diff --git a/src/keys.ts b/src/keys.ts index 03b4103..c912eff 100644 --- a/src/keys.ts +++ b/src/keys.ts @@ -1,5 +1,5 @@ export interface LocaleKeys { - [key: string]: unknown + [key: string]: string | LocaleKeys } export default LocaleKeys export const localeKeys: LocaleKeys = {} diff --git a/t.ts b/t.ts deleted file mode 100644 index 07ce420..0000000 --- a/t.ts +++ /dev/null @@ -1,5 +0,0 @@ -import Translator from './src/index.js' - -const t = Translator('en') - -console.log(t(''))