I'm converting response to a Class like this:
private mapSingle(response: SingleResponse): CodeExample {
var authorResponse = response.modular_content[response.item.elements.author.value as string];
var author = new Author(authorResponse.system, authorResponse.elements.name.value, authorResponse.elements.image.value);
return new CodeExample(
response.item.system,
response.item.elements.code.value,
author,
response.item.elements.versions.value as CodeExampleCategory[],
response.item.elements.title.value,
response.item.elements.versions.value as CodeExampleVersion[]
);
}
Even though this works perfectly fine, I'm hoping there is a better way to do this so that I don't need to declare the author response before the constructor. Ideally I would like to put my own function in constructor and resolve this "inline". Is this possible?