0

I have this typescript data in a config file:

const filtersTracking = {
 [SEARCH_TYPE_ARTICLES]: {
 orderBy: {
 category: 'Suche Filter Rechtstipps',
 action: 'Sortierung Auswahl',
 },
 practiceAreas: {
 category: 'Suche Filter Rechtstipps',
 action: 'Rechtsgebiet Auswahl',
 },
 ratingAverage: {
 category: 'Suche Filter Rechtstipps',
 action: 'Bewertung Sterne',
 },
 ratingCount: {
 category: 'Suche Filter Rechtstipps',
 action: 'Anzahl Bewertungen',
 },
 publicationYear: {
 category: 'Suche Filter Rechtstipps',
 action: 'Publikation',
 },
 isGuide: {
 category: 'Suche Filter Rechtstipps',
 action: 'Ratgeber',
 },
 hasVideo: {
 category: 'Suche Filter Rechtstipps',
 action: 'Video',
 },
 internationalLaws: {
 category: 'Suche Filter Rechtstipps',
 action: 'Internationales Recht',
 },
 },
}

what I am trying to do is to get 'category' and 'action' data, I have tried following methods but none worked for me:

  1. filtersTracking[SEARCH_TYPE_ARTICLES][key]
  2. filtersTracking[SEARCH_TYPE_ARTICLES].key
  3. filtersTracking[SEARCH_TYPE_ARTICLES].[key]

here 'key' is a dynamic variable and I am getting the data key(e.g 'orderBy' or 'practiceArea') inside 'key'.

public function(key) {
console.log(filtersTracking[SEARCH_TYPE_ARTICLES][key])
}
asked Feb 25, 2022 at 10:48
2
  • "none worked for me" What is the error message? What is the value of the variable SEARCH_TYPE_ARTICLES? Is it defined when you call it? Commented Feb 25, 2022 at 10:53
  • BTL, export const SEARCH_TYPE_USERS = 'users'; error message : Element implicitly has an 'any' type because expression of type 'string | number' can't be used to index type Commented Feb 25, 2022 at 10:54

1 Answer 1

1

According to your comment BTL, export const SEARCH_TYPE_USERS = 'users'; error message : Element implicitly has an 'any' type because expression of type 'string | number' can't be used to index type

This post should help you:

Element implicitly has an 'any' type because expression of type 'string' can't be used to inde

answered Feb 25, 2022 at 11:18
Sign up to request clarification or add additional context in comments.

2 Comments

ThankYou so much bro, that post helped me out. So, we can do it like this filtersTracking[SEARCH_TYPE_ARTICLES][key as keyof typeof filtersTracking]
No probs, please set this as an answer if it solves your issue

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.