The arrayBuffer(), stream(), and text() of Blob are missing from the type definition. (See https://w3c.github.io/FileAPI/#stream-method-algo and following for details.)
TypeScript Version: 3.7.0-dev.20191021
Search Terms: blob text method typescript
Code
declare var x: Blob;
x = new Blob();
x.slice();
x.text();
Expected behavior: Program typechecks.
Actual behavior: error TS2339: Property 'text' does not exist on type 'Blob'.
Playground Link: https://www.typescriptlang.org/play/?ts=3.7.0-dev.20191021#code/CYUwxgNghgTiAEA3W8AeAueAhCB7ARgNwCwAUGavALzwB2IA7tnvgBQCUJpqAdAM4QAlmBAcuvAC4hUEsUA
Related Issues: none
According to the MDN these methods are still only part of a Working Draft and not well supported.
https://developer.mozilla.org/en-US/docs/Web/API/Blob/stream
https://developer.mozilla.org/en-US/docs/Web/API/Blob/text
https://developer.mozilla.org/en-US/docs/Web/API/Blob/arrayBuffer
You're right.
What's the best way for me to "monkeypatch" these into my code if I really want to make use of them? I imagine I can't just redeclare interface Blob and expect everything to just work?
You should be able to use declaration merging for this and provide your own declarations:
https://www.typescriptlang.org/docs/handbook/declaration-merging.html
Thank you for the pointer!
Ran into this same problem in my create-react-app
Added this to src/react-app-env.d.ts
interface Blob {
text: () => Promise<string>
}
You could also call it like x['text'](), if you don't want to redeclare the interface.
Most helpful comment
You could also call it like
x['text'](), if you don't want to redeclare the interface.