This might have been asked before, but I have a situation where I have an object type which my backend expects like so:
type TagTypeThatMyBackendWants = {
id: string;
name: string;
}
It consist of two string type keys, the key names being id and name. I get these type of Tag-objects from my backend and my backend also expects objects like these back. Now, the problem is that I am using a library that handles these tags, but the library expects the objects to look like this:
type TagTypeThatALibraryWants = {
id: string;
text: string;
}
So it is basically the same object, but instead of a name key with a type of string, the library expects a text key with a type of string. I kind of already solved this by doing some custom mapping back and forth, but this raised the question if there is an “official” or a recommended way to do something like this – like casting from one object type to another, with the ability to tell TypeScript that the name-key “maps” to text-key and vice versa.