Encountering an issue when defining a custom property on an array or object in typescript, leading to the error message:
"Property x does not exist on type Object (or type Array)"
For instance, working with typescript in Angular and having a defined scope based on Angular's type definition file:
scope:ng.IScope
Attempting to add a new property to scope like so:
scope.anotherProperty = "string";
This results in the aforementioned error. Solutions include using:
scope["anotherProperty"] = "string";
OR
(<any>scope).anotherProperty = "string;
Similarly, encountering challenges within a d3 graph setup:
function panZoomNode (node:any) {
for (var i = 0; i < renderedNodes.length; i++) {
if (node.id === renderedNodes[i].id) {
}
}
}
Seeking to change the (node:any) parameter to something like:
(node:Object)
However, this leads to an error stating "property id does not exist on type Object". While temporary fixes are available, is there a more streamlined approach or best practice in typescript to handle both arrays and objects efficiently?
Appreciate any insights.