diff --git a/docs/type-safety.md b/docs/type-safety.md index 64e5151..43532dd 100644 --- a/docs/type-safety.md +++ b/docs/type-safety.md @@ -14,7 +14,9 @@ export interface TranslationsKeys { // Specify here all the namespaces you have... } -export interface TranslateFunction { +type TranslationNamespace = keyof TranslationsKeys; + +export interface TranslateFunction { ( key: TranslationsKeys[Namespace], ...rest: Tail> @@ -22,20 +24,20 @@ export interface TranslateFunction { (template: TemplateStringsArray): string }; -export interface TypeSafeTranslate +export interface TypeSafeTranslate extends Omit { t: TranslateFunction } declare module 'next-translate/useTranslation' { export default function useTranslation< - Namespace extends keyof TranslationsKeys + Namespace extends TranslationNamespace >(namespace: Namespace): TypeSafeTranslate } declare module 'next-translate/getT' { export default function getT< - Namespace extends keyof TranslationsKeys + Namespace extends TranslationNamespace >(locale?: string, namespace: Namespace): Promise> } ``` @@ -46,4 +48,4 @@ Then type safety should work: Screenshot 2023-07-17 at 19 22 00 -Reference: https://github.com/aralroca/next-translate/pull/1108 +Reference: