title: Is there any way to target the plain JavaScript object type in TypeScript?
body: <h3>UPDATE 2021</h3>
  <p>For a working solution using newer features see this answer <a href="https://stackoverflow.com/a/59647842/1323504">https://stackoverflow.com/a/59647842/1323504</a></p>
  <hr />
  <p>I'm trying to write a function where I'd like to indicate that it returns <em>some kind of</em> plain JavaScript object. The object's signature is unknown, and not interesting for now, only the fact that it's a plain object. I mean a plain object which satisfies for example jQuery's <code>isPlainObject</code> function. For example</p>
  <pre><code>{ a: 1, b: &quot;b&quot; }
  </code></pre>
  <p>is a plain object, but</p>
  <pre><code>var obj = new MyClass();
  </code></pre>
  <p>is not a &quot;plain&quot; object, as its <code>constructor</code> is not <code>Object</code>. jQuery does some more precise job in <code>$.isPlainObject</code>, but that's out of the question's scope.</p>
  <p>If I try to use <code>Object</code> type, then it will be compatible to any custom object's too, as they're inherited from <code>Object</code>.</p>
  <p>Is there a way to target the &quot;plain object&quot; type in TypeScript?</p>
  <p>I would like a <em>type</em>, which would satisfy this for example.</p>
  <pre><code>var obj: PlainObject = { a: 1 }; // perfect
  var obj2: PlainObject = new MyClass(); // compile-error: not a plain object
  </code></pre>
  <p><strong>Use case</strong></p>
  <p>I have kind of a strongly-typed stub for server-side methods, like this. These stubs are generated by one of my code generators, based on ASP.NET MVC controllers.</p>
  <pre><code>export class MyController {
    ...
    static GetResult(id: number): JQueryPromise&lt;PlainObject&gt; {
      return $.post(&quot;mycontroller/getresult&quot;, ...);
    }
    ...
  }
  </code></pre>
  <p>Now when I call it in a consumer class, I can do something like this.</p>
  <pre><code>export class MyViewModelClass {
    ...
    LoadResult(id: number): JQueryPromise&lt;MyControllerResult&gt; { // note the MyControllerResult strong typing here
      return MyController.GetResult(id).then(plainResult =&gt; new MyControllerResult(plainResult));
    }
    ...
  }
  </code></pre>
  <p>And now imagine that the controller method returns <code>JQueryPromise&lt;any&gt;</code> or <code>JQueryPromise&lt;Object&gt;</code>. And now also imagine that by accident I write <code>done</code> instead of <code>then</code>. Now I have a hidden error, because the viewmodel method will not return the correct promise, but I won't get a compile-error.</p>
  <p>If I had this imaginary <code>PlainObject</code> type, I'd expect to get a compile error stating that <code>PlainObject</code> cannot be converted to <code>MyControllerResult</code>, or something like that.</p>