title: enforce property order in a typescript interface
body: <p>I am building a typescript interface to an API that I do not control. The API is xml based and expects properties in a particular order. These properties are not all required, but if they exist they must come in their proper order. Example:</p>
  
  <p><a href="https://i.stack.imgur.com/Rw4qs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Rw4qs.png" alt="enter image description here"></a></p>
  
  <p>database and query are required, the others are not but if they exist <code>rowOffset</code> must come before <code>rowCount</code> and <code>rowCount</code> before <code>formatValues</code></p>
  
  <pre><code>// Valid request
  &lt;database&gt;my data&lt;/database&gt;
  &lt;query&gt;select * from some_table&lt;/query&gt;
  &lt;formatValues&gt;true&lt;/formatValues&gt;
  
  // Valid request
  &lt;database&gt;my data&lt;/database&gt;
  &lt;query&gt;select * from some_table&lt;/query&gt;
  &lt;rowOffset&gt;1&lt;/rowOffset&gt;
  &lt;formatValues&gt;true&lt;/formatValues&gt;
  
  // Invalid request
  &lt;database&gt;my data&lt;/database&gt;
  &lt;query&gt;select * from some_table&lt;/query&gt;
  &lt;formatValues&gt;true&lt;/formatValues&gt;
  &lt;rowOffset&gt;1&lt;/rowOffset&gt; // formatValues must come after rowOffset if it exists
  </code></pre>
  
  <p>The typescript signature for this request looks like this</p>
  
  <pre><code>sqlQuery(database: string, query: string, options: object) : Promise
  </code></pre>
  
  <p>database and query are required and must be specified, the other options go to an object and we extend it with our required params and convert the whole thing to xml and send it on its way. The problem is that the options will be converted to xml attributes in order and so I need to enforce the order of the attributes, without enforcing the existence of these attributes.</p>
  
  <p>I thought a map could do the trick, but I can't figure out how to make a custom type from a map. I could do an interface</p>
  
  <pre><code>interface OptionalParams {
      rowOffset? : string,
      rowCount? : string,
      formatValues? :string,
  }
  </code></pre>
  
  <p>but this won't enforce the order they exist in relative to each other. Is there any such type that can do this?</p>