title: How to type check a binary type alias in Typescript
body: <p>I would like to depend a condition on the given type of an argument, but since all possible arguments are the same binary type (number), I look for a way to create some kind of a type alias, that can be checked for. </p>
  
  <p>This is the initial idea, that doesn't work, because typescript is compiled into javascript and thus <code>bonus</code> will always be the javascript type <code>number</code>.</p>
  
  <pre class="lang-js prettyprint-override"><code>    type Percentage = number;
  
      class Foo {
        applyBonus(bonus: Percentage | number) {
          if (typeof bonus === 'Percentage') {
            console.log('Percent');
          } else {
            // it's always number, because at execution time we're in javascript land here
            console.log('number'); 
          } 
        }
      }
  
      let bar = new Foo();
      bar.applyBonus(5);
      bar.applyBonus(6 as Percentage);
  </code></pre>
  
  <p>This question is mainly focused on the possibilities of the typescript language, and if this can be solved with typescript features. It would be easily possible to use an object like <code>{value:6,type:'percent'}</code> instead of a binary type number. </p>