title: How do you cast data from Firebase to a fully typed Map?
body: <p>I have data from Firebase that looks something like this:</p>
  <pre><code>{
      &quot;foo&quot;: {
          1: true,
          2: false
      },
      &quot;bar&quot;: {
          3: true,
          4: false
      }
  }
  </code></pre>
  <p>If I'm not mistaken, this should be a <code>Map&lt;String, Map&lt;int, bool&gt;&gt;</code>. I'm trying to use this function to safely cast it:</p>
  <pre><code>T castWithDefaultValue&lt;T&gt; (val, T defaultValue) =&gt; val is T ? val : defaultValue;
  
  var castData = castWithDefaultValue&lt;Map&lt;String, Map&lt;int, bool&gt;&gt;&gt;(dataFromFirebase, {});
  </code></pre>
  <p>But it fails, always returning the default value. The only types I can get to work for either the key or the value are <code>Object?</code> and <code>dynamic</code>, but I want more type safety. How do I get it to what I want it to be?</p>