title: How do I specify "any non-nullable type" as a generic type parameter constraint?
body: <p>The post is specific to C# 8. Let's assume I want to have this method:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public static TValue Get&lt;TKey, TValue&gt;(
    this Dictionary&lt;TKey, TValue&gt; src, 
    TKey key, 
    TValue @default
  ) 
  =&gt; src.TryGetValue(key, out var value) ? value : @default;
  </code></pre>
  
  <p>If my <code>.csproj</code> looks like this (i.e. C# 8 and nullable types are enabled, all warnings are errors):</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Project Sdk="Microsoft.NET.Sdk"&gt;
    &lt;PropertyGroup&gt;
      &lt;TargetFramework&gt;netcoreapp3.0&lt;/TargetFramework&gt;
      &lt;LangVersion&gt;8&lt;/LangVersion&gt;
      &lt;Nullable&gt;enable&lt;/Nullable&gt;
      &lt;WarningsAsErrors&gt;true&lt;/WarningsAsErrors&gt;
    &lt;/PropertyGroup&gt;
    …
  &lt;/Project&gt;
  </code></pre>
  
  <p>This code will produce the following build-time error:</p>
  
  <blockquote>
    <p><code>DictionaryEx.cs</code>(28, 78): [CS8714] The type 'TKey' cannot be used as type parameter 'TKey' in the generic type or method 'Dictionary'. Nullability of type argument 'TKey' doesn't match 'notnull' constraint.</p>
  </blockquote>
  
  <p>Is there any way to specify that <code>TKey</code> has to be a non-nullable type?</p>