Next-intl type error accessing field with dynamic string
Unanswered
Rex posted this in #help-forum
RexOP
en.json
page.tsx
Error:
"Languages": {
"en": "English",
"it": "Italian",
"es": "Spanish",
"fr": "French",
"de": "German",
"ru": "Russian",
"dk": "Danish",
"se": "Swedish",
"in": "Hindi",
"cn": "Chinese",
"jp": "Japanese",
"another_language": "Another language"
},
...page.tsx
import { useTranslations } from 'next-intl';
const l = useTranslations('Languages');
...
l(word.language) -> here I got the errorError:
Type error: Argument of type 'string' is not assignable to parameter of type 'MessageKeys<{ en: string; it: string; es: string; fr: string; de: string; ru: string; dk: string; se: string; in: string; cn: string; jp: string; another_language: string; }, "it" | "en" | "es" | "fr" | "de" | "ru" | ... 5 more ... | "another_language">'.
143 | <p className="object-field">
144 | l(word.language)
| ^
147 | </p>
148 | </div>
Error: Command "npx prisma generate && next build" exited with 1