title: Is there a way to create nominal types in TypeScript that extend primitive types?
body: <p>Say I have two types of numbers that I'm tracking like <code>latitude</code> and <code>longitude</code>.  I would like to represent these variables with the basic <code>number</code> primitive, but disallow assignment of a <code>longitude</code> to  a <code>latitude</code> variable in typescript.</p>
  
  <p>Is there a way to sub-class the <code>number</code> primitive so that typescript detects this assignment as illegal? Someway to coerce nominal typing so that this code fails?</p>
  
  <pre><code>var longitude : LongitudeNumber = new LongitudeNumber();
  var latitude : LatitudeNumber;
  latitude = longitude; // &lt;-- type failure
  </code></pre>
  
  <p>The answer to <a href="https://stackoverflow.com/questions/23306562/how-to-extend-a-primitive-type-in-typescript">"How to extend a primitive type in typescript?"</a> seems like it will put me in the right direction, but I am not sure how to extend that solution to create distinct nominal sub-types for different <a href="http://www.joelonsoftware.com/articles/Wrong.html" rel="noreferrer"><em>kinds</em></a> of numbers.</p>
  
  <p>Do I have to wrapper the primitive?  If so, can I make it behave somewhat seamlessly like a normal number or would I have to reference a sub-member?  Can I just somehow create a typescript compile-time number subclass?</p>