Answer the question
In order to leave comments, you need to log in
How to correctly specify the key type in TypeScript?
interface LangKey {
header: string,
content: string
}
interface Lang {
en: LangKey,
ru: LangKey,
}
const translation: Lang = {
en: {
'header': 'Header content',
"content": 'Content'
},
ru: {
'header': 'Хедер контент',
"content": 'Контент'
}
}
export const getTranslation = (text: string, lang:string) => {
return translation[lang][text];
}
return translation[lang][text];
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question