title: Using TypeScript, how do I strongly type mysql query results
body: <p>I'm new to Typescript and can't figure out if I'm strongly typing the results of my query correctly or not.  Here's the essence of my code...</p>
  
  <pre><code>import mysql2, {Pool} from "mysql2";
  const pool: Pool = mysql2.createPool({...}).promise();
  
  interface IUser {
      uid   : number;
      uname : string;
  }
  
  class UserController {
  
      public async getUser(id: number): Promise&lt;IUser&gt; {
          const [rows]: Array&lt;{rows: IUser}&gt; = await pool.query(
              "SELECT * FROM `users` WHERE `email` = ?",["me@me.org"]);        
          return rows;
      }
  }
  </code></pre>
  
  <p>The TypeScript compiler (3.3.1) complains about my <code>return rows</code> statement.</p>
  
  <blockquote>
    <p>TS2740: Type '{rows: IUser;}' is missing the following properties from
    type 'IUser': uid and uname.</p>
  </blockquote>
  
  <p>If I ignore the return with <code>// @ts-ignore</code> everything works great. I get my object back just fine without any errors.</p>
  
  <p>Am I doing something wrong?</p>
  
  <hr>
  
  <p>I made some changes, but I'm honestly confused as to why TypeScript doesn't complain.  It doesn't seem right at all.  </p>
  
  <pre><code>    class UserController {
  
          public async getUser(id: number): Promise&lt;{rows: IUser}&gt; {
              const [rows]: Array&lt;{rows: IUser}&gt; = await pool.query(
                  "SELECT * FROM `users` LIMIT 3");        
              return rows;
          }
      }
  </code></pre>
  
  <p>Is this right???</p>
  
  <hr>
  
  <p>So, no that's all wrong.</p>
  
  <p>When I thought about <code>query</code> returning <code>[rows, fields]</code> it started too make a little more sense. I think @joesph-climber is correct with some tweaked syntax.</p>
  
  <p>This works and makes sense to me...</p>
  
  <pre><code>    class UserController {
  
          public async getUser(id: number): Promise&lt;Array&lt;{rows: IUser}&gt;&gt; {
              const [rows]: [Array&lt;{rows: IUser}&gt;] = await pool.query(
                  "SELECT * FROM `users` LIMIT 3");        
              return rows;
          }
      }
  </code></pre>
  
  <p>This also works and is probably more readily understandable.</p>
  
  <pre><code>    class UserController {
  
          public async getUser(id: number): Promise&lt;IUser[]&gt; {
              const [rows]: [IUser[]] = await pool.query(
                  "SELECT * FROM `users` LIMIT 3");        
              return rows;
          }
      }
  </code></pre>