Skip to content

Commit

Permalink
Refactor translation types in next-translate.d.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
hichemfantar committed Jan 25, 2024
1 parent cd74d89 commit 1c8cc27
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions examples/with-app-directory/next-translate.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,29 @@ export interface TranslationsKeys {
// Specify here all the namespaces you have...
}

export interface TranslateFunction<Namespace extends keyof TranslationsKeys> {
type TranslationNamespace = keyof TranslationsKeys;

export interface TranslateFunction<Namespace extends TranslationNamespace> {
(
key: TranslationsKeys[Namespace],
...rest: Tail<Parameters<Translate>>
): string
<T extends string>(template: TemplateStringsArray): string
};

export interface TypeSafeTranslate<Namespace extends keyof TranslationsKeys>
export interface TypeSafeTranslate<Namespace extends TranslationNamespace>
extends Omit<I18n, 't'> {
t: TranslateFunction<Namespace>
}

declare module 'next-translate/useTranslation' {
export default function useTranslation<
Namespace extends keyof TranslationsKeys
Namespace extends TranslationNamespace
>(namespace: Namespace): TypeSafeTranslate<Namespace>
}

declare module 'next-translate/getT' {
export default function getT<
Namespace extends keyof TranslationsKeys
Namespace extends TranslationNamespace
>(locale?: string, namespace: Namespace): Promise<TranslateFunction<Namespace>>
}

0 comments on commit 1c8cc27

Please sign in to comment.