Object.keys Typescript Error #1114
Unanswered
matej-bittner
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there,
After spending several hours trying to solve this problem, I haven't had much luck.
I'm trying to map data to a navigation menu, but I don't want to have to manually specify the number of links each time I add something new in the future.
In my 'en.json' file, I have the following data:
{ "Navigation": { "appName": "xxx", "userButton": "My Account", "NavLinks": { "0": { "title": "about", "link": "#" }, "1": { "title": "demo", "link": "#" }, "2": { "title": "pricing", "link": "#" } } } }
and my navigation component:
`
const t = useTranslations("Navigation.NavLinks");
const messages = useMessages();
const keys = Object.keys(messages.Navigation.NavLinks);
`
.I'm encountering an error with the constant keys. The message says "Property NavLinks does not exist on type string or AbstractIntlMessages"
The only way I can get it to work without errors is by moving the NavLinks inside en.json to a separate object (outside of Navigation). However, this isn't a very elegant solution in my opinion. Thanks for any help!"
Beta Was this translation helpful? Give feedback.
All reactions