I'm trying to create a type of translation object, and here's how I want it to be.
const noTranslations = {
phonenumber: "Telefonnummer",
loginScreen: {
title: "Logg inn",
sendCode: "Send kode",
login: "Logg inn",
},
profileScreen: {
title: "Profil",
},
logout: "Logg ut",
required: "Påkrevd",
};
I want to be able to type check a string with the following format:
this should pass in the typescript compiler:
"loginScreen.title"
this should fail:
"loginScreen.thisPropertyIsNotWithinTheObject"
Here's how I've come this far.
type transKeyType =
| `${keyof typeof noTranslations}.${keyof typeof noTranslations.loginScreen}`
| `${keyof typeof noTranslations}`;
This works for only the loginScreen, and I do not want to extend this with another line for each object from the root.. Is it possible to do this dynamically?