title: Blob vs. Blob Source in Google Apps Script
body: <p>I'm using <a href="https://developers.google.com/apps-script/guides/clasp" rel="nofollow noreferrer">clasp</a> which lets you develop your Google Apps Script in typescript.</p>
  <p>In my script, I convert a google sheet into a Blob of a PDF, then upload that to Google Drive.</p>
  <p>The code runs fine, but I'm having trouble working with the <a href="https://developers.google.com/apps-script/reference/base/blob" rel="nofollow noreferrer">Blob</a> vs. <a href="https://developers.google.com/apps-script/reference/base/blob-source" rel="nofollow noreferrer">BlobSource</a> types properly to keep TypeScript happy.</p>
  <h2>Setup</h2>
  <p>I've declared some type abbreviations like this at the start of my file:</p>
  <pre><code>type Sheet = GoogleAppsScript.Spreadsheet.Sheet;
  type SS = GoogleAppsScript.Spreadsheet.Spreadsheet;
  type GBlob = GoogleAppsScript.Base.Blob;
  type GBlobSource = GoogleAppsScript.Base.BlobSource;
  </code></pre>
  <p>I have a a function with this signature:</p>
  <pre><code>getPdfBlob(sheet: Sheet, pdfName: string): GBlob
  </code></pre>
  <p>I do something like this in my code:</p>
  <pre><code>var pdfBlob = getPdfBlob(mySheet, 'aPdfName');
  var file = DriveApp.createFile(pdfBlob);
  </code></pre>
  <h2>Problem</h2>
  <p>My IDE complains that <code>DriveApp.createFile</code> wants type <code>BlobSource</code> as a parameter, not <code>Blob</code>.</p>
  <p>If I try to casting Blob into BlobSource like this:</p>
  <pre><code>var file = DriveApp.createFile(&lt;GBlobSource&gt;pdfBlob);
  </code></pre>
  <p>My IDE complains:</p>
  <blockquote>
  <p>Conversion of type 'Blob' to type 'BlobSource' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.</p>
  <p>Property 'getBlob' is missing in type 'Blob' but required in type 'BlobSource'.</p>
  </blockquote>
  <p>As I mentioned, the code runs fine this way. I just want to get my type declarations correct so TypeScript continues to add value.</p>
  <p>From <a href="https://developers.google.com/apps-script/reference/base/blob-source" rel="nofollow noreferrer">the documentation</a> it looks like <code>Blob</code> <em>implements</em> <code>BlobSource</code> so I'm unsure why I can't &quot;upcast&quot; back to <code>BlobSource</code>. Could this be an error with the TypeScript definitions?</p>
  <p>Any input on what the issue is here / the proper way to handle it would be much appreciated.</p>