Skip to content

Commit

Permalink
[superagent] Fix Blob error
Browse files Browse the repository at this point in the history
At the moment, some users' builds fail, because `Blob` isn't defined as
a global in Node.js - it sits in the [`buffer`][1] package.

This change adds an import from `buffer` to fix this issue.

Note that I think the build was incorrectly passing before because of
a [leaky interface in `stream/consumers`][2].

[1]: https://nodejs.org/api/buffer.html#class-blob
[2]: DefinitelyTyped#55311 (comment)
  • Loading branch information
alecgibson committed Jan 19, 2022
1 parent 3f78c2c commit 31c62f0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions types/superagent/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as fs from "fs";
import * as http from "http";
import * as stream from "stream";
import * as cookiejar from "cookiejar";
import { Blob } from 'buffer';

type CallbackHandler = (err: any, res: request.Response) => void;

Expand Down
3 changes: 2 additions & 1 deletion types/superagent/superagent-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import request = require("superagent");
import * as fs from "fs";
import assert = require("assert");
import { Agent } from "https";
import { Blob } from "buffer";

// Examples taken from https://github.com/visionmedia/superagent/blob/gh-pages/docs/index.md
// and https://github.com/visionmedia/superagent/blob/master/Readme.md
Expand Down Expand Up @@ -219,7 +220,7 @@ request.get("http://example.com/search").retry(2, callback).end(callback);
})();

// Attaching files
declare const blob: Blob;
const blob = new Blob([]);
request
.post("/upload")
.attach("avatar", "path/to/tobi.png", "user.png")
Expand Down

0 comments on commit 31c62f0

Please sign in to comment.