In my Typescript class for an Angular version 5 project, I have a JavaScript function that generates a style object. Here is the function:
private createCircle(parameters: any): any {
return new Circle({
radius: parameters.radius,
snapToPixel: parameters.snapToPixel,
fill: new Fill(parameters.fill),
stroke: new Stroke(parameters.stroke)
});
}
The classes Circle
, Fill
, and Stroke
are third-party libraries. The function parameter parameters
is a JSON object structured like this:
{
"radius": 10,
"snapToPixel": true,
"fill": {
"color": "rgba(255, 255, 0, 0.4)"
},
"stroke": {
"color": "red",
"width": 1,
"lineDash": null,
"lineCap": "round",
"lineJoin": "round",
"miterLimit": 10
}
}
Is it possible to directly cast this JSON object to the Circle
class? The instances of Circle
, Fill
, and Stroke
should be created using the new
keyword.