Created
May 3, 2020 16:04
-
-
Save rarous/c037f2939816d48a6d8df19b37ced352 to your computer and use it in GitHub Desktop.
Ukázka typové masturbace, kvůli špatně otypované knihovně
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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