title: Convert a String | Null to Nullable Number
body: <p>Using Typescript I am looking for a short approach to covert <code>string | null</code> to a nullable number.</p>
  <p>I tried to convert the string to number and if it not value then convert it to <code>undefined</code> (<a href="https://www.typescriptlang.org/play?module=6#code/MYGwhgzhAEDKCmAnAbgS2PaBvAUNaA5vAC4ByAriCAGpgjnwAUAlNAFzQTGKoB2B0AD7RelENjz5oiEuUS8RYgNySAvpKLFY3PgVr0mrDlx78hiqhKnTZ86ACIATAAZ7K-OtXQcOUJBgAQgD2QQDWVtDAQQAm8AD8HKIAtgBGSCrqOCAknEhoGBwIKOiYALwi8ADucHklLCpZOSkhoQCMHMFh0OVYkTHwHADUAIQQtRgAdJrapnp0DCzQcXHQ5LyxAGZ88NHQqg1RvBBB2RMgQQSMzWGtzA3ZxNDXoY4dLd3YfbFDo%20PwUyQKFR9AtWMtVut4FteDs9gcgkcTv9zpdno47kA" rel="nofollow noreferrer">Online Example</a>).</p>
  <pre><code>class Service {
    getNullValue() : string | null {
      return null;
    }
    getStringValue() : string | null {
      return &quot;20&quot;;
    }
  } 
  
  class Book {
    code?: number;
  }
  
  let service: Service = new Service();
  
  let book1: Book = { code: +!service.getStringValue() ?? undefined };
  
  console.log(book1);
  
  let book2: Book = { code: +!service.getNullValue() ?? undefined };
  
  console.log(book2);
  </code></pre>
  <p>On the console I get:</p>
  <pre><code>{ &quot;code&quot;: 0 }
   
  { &quot;code&quot;: 1 } 
  </code></pre>
  <p>Is there a way to do this?</p>