title: Best way to solve typescript error - property does not exist on type
body: <p>I have several different situations where I am trying to define a self made property on an array or object in typescript but commonly get the error:</p>
  
  <p>"Property x does not exist on type Object (or type Array)"</p>
  
  <p>For example I am using typescript in Angular and have a defined scope based on the Angular type definition file:</p>
  
  <pre><code>scope:ng.IScope
  </code></pre>
  
  <p>But then when I try to create a new property on scope by doing:</p>
  
  <pre><code>scope.anotherProperty = "string";
  </code></pre>
  
  <p>I get the error mentioned above. I know I can solve it by doing one of the following:</p>
  
  <pre><code>scope["anotherProperty"] = "string";
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>(&lt;any&gt;scope).anotherProperty = "string;
  </code></pre>
  
  <p>Another example is when I have something like this within my d3 graph:</p>
  
  <pre><code>function panZoomNode (node:any) {
              for (var i = 0; i &lt; renderedNodes.length; i++) {
                  if (node.id === renderedNodes[i].id) {
  
                      }
                  }
          }
  </code></pre>
  
  <p>Ideally, I would like to change that (node:any) parameter to something like:</p>
  
  <pre><code>(node:Object)
  </code></pre>
  
  <p>But when I do that, I get an error saying "property id does not exist on type Object". I know I can correct it with the solutions I mentioned above but that seems kind of sloppy to me. Is there a better way or best typescript way of getting those to run correctly for both arrays and objects?</p>
  
  <p>Thanks</p>