When working with raw data in TypeScript (originally a JSON file and imported using
import * as raw_data from './json_file.json'
):
let raw_data: object = {"a": {"name": "Name a", "desc": "Description a"}, "b": {"name": "Name b", "desc": "Description b"} }
I need to extract a map of keys (as strings) and the custom objects defined by the interface AnObject
:
interface AnObject {
name: string;
description: string;
}
How can I achieve this in TypeScript?
I've attempted:
let myObject: Map<string, AnObject> = raw_data as Map<string, AnObject>;
and also
let myObject: Map<string, AnObject> = <Map<string, AnObject>>raw_data
but have been unsuccessful so far. The object remains as an object
and myObject.size
returns undefined.