title: Declare/change the current type of an object in Typescript
body: <p>Typescript is great about type checking, but sometimes I know better than it does.</p>
  
  <p>I'd like to be able to say "From this scope on, pretend variable x is of type y"</p>
  
  <pre><code>const array = ["foo", {bar: "quz"}];
  array.forEach((it) =&gt; {
    if (it !== "foo") {
      declare it: {bar: "quz"}; // not real code, what I'd like to do
      it.bar; // Error: Property 'bar' does not exist on type 'string | { bar: string; }'
    } 
  });
  </code></pre>
  
  <hr>
  
  <ul>
  <li>I know I could write a function to do <code>isBarQuz(checkMe: any): checkMe is {bar: "quz"}</code>;</li>
  <li>I also know I could define my array types.</li>
  <li>I also know that in this example, my array could be <code>const array = [...] as const</code></li>
  <li>I could also define to a new variable, then change all my code to use that one instead</li>
  </ul>
  
  <p>I don't want to do any of these things.  I just want to gloss over a bit of type checking and get on with my work.  How can I do this?</p>