title: How to restrict object types based on a value in the object?
body: <p>For now I'm using this type alias:</p>
  
  <pre><code>export type Country = {
    name: 'USA' | 'Russia' | 'Bulgaria' | 'Romania' | 'Austria' | 'Great Britain' | 'Italy',
    code: 'us' | 'ru' | 'bg' | 'ro' | 'au' | 'gb' | 'it'
  };
  </code></pre>
  
  <p>But it allows to create incorrect objects:</p>
  
  <pre><code>{ name: 'USA', code: 'ru'}
  </code></pre>
  
  <p>What is the best way to make a type for this purpose?</p>