Skip to content

Instantly share code, notes, and snippets.

@rarous
Created May 3, 2020 16:04
Show Gist options
  • Save rarous/c037f2939816d48a6d8df19b37ced352 to your computer and use it in GitHub Desktop.
Save rarous/c037f2939816d48a6d8df19b37ced352 to your computer and use it in GitHub Desktop.
Ukázka typové masturbace, kvůli špatně otypované knihovně
// drive().files.export je otypovaná jako Promise<void>,
// ale skutečný typ je dán parametrem v { responseType: "stream" }
// Aby se uspokojil kompilátor, musíme nejprve typ zázračně zapomenout
// a pak si ho přetypovat dle libosti. Masturbace.
async function convertToPdf(fileId: string): Promise<fs.ReadStream> {
const response: unknown = await drive().files.export(
{ fileId, mimeType: "application/pdf" },
{ responseType: "stream" }
);
return (response as Response<fs.ReadStream>).data;
}
interface Response<T> {
data: T;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment