I'm using clasp which lets you develop your Google Apps Script in typescript.
In my script, I convert a google sheet into a Blob of a PDF, then upload that to Google Drive.
The code runs fine, but I'm having trouble working with the Blob vs. BlobSource types properly to keep TypeScript happy.
Setup
I've declared some type abbreviations like this at the start of my file:
type Sheet = GoogleAppsScript.Spreadsheet.Sheet;
type SS = GoogleAppsScript.Spreadsheet.Spreadsheet;
type GBlob = GoogleAppsScript.Base.Blob;
type GBlobSource = GoogleAppsScript.Base.BlobSource;
I have a a function with this signature:
getPdfBlob(sheet: Sheet, pdfName: string): GBlob
I do something like this in my code:
var pdfBlob = getPdfBlob(mySheet, 'aPdfName');
var file = DriveApp.createFile(pdfBlob);
Problem
My IDE complains that DriveApp.createFile wants type BlobSource as a parameter, not Blob.
If I try to casting Blob into BlobSource like this:
var file = DriveApp.createFile(<GBlobSource>pdfBlob);
My IDE complains:
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.
Property 'getBlob' is missing in type 'Blob' but required in type 'BlobSource'.
As I mentioned, the code runs fine this way. I just want to get my type declarations correct so TypeScript continues to add value.
From the documentation it looks like Blob implements BlobSource so I'm unsure why I can't "upcast" back to BlobSource. Could this be an error with the TypeScript definitions?
Any input on what the issue is here / the proper way to handle it would be much appreciated.
.d.tsfiles to reflect that Blob implements blobsource, and see if that resolves the issue. If so, make your PR to the DefinitelyTyped repo and fix it for everyone :) - tehhowch