Our backend is returning most string data as json object strings where each key represents a language code that may or may not exist on a particular database record. For example, it will come down as:
{
"id": "4788fb8d-fb63-4189-a9e8-68624180852e",
"description": "{"en":"description of co","es":"descripciĆ³n de la co"}", "options": "[{}]"
}
Or:
{
"id": "4788fb8d-fb63-4189-a9e8-68624180852e",
"description": "{"en":"description of company"}",
"options": [{"en":"english text"},{"en":"english text","es":"spanish text"},{"en":""}]
}
etc..
What is an appropriate way to represent this type across our whole web app so all our objects can be safely worked with? I’m sure this is probably a bit naive:
interface StringType {
en: string | undefined;
es: string | undefined;
de: string | undefined;
}
interface Customer {
id: string;
description: StringType;
options: StringType[]; //
}
And how would I narrow the keys to only be our supported language codes, for example ‘en’ or ‘es’ or ‘de’ instead of any string?