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].

Note that I've had to disable the linter's `no-outside-dependencies`
because of a [known false positive on `buffer`][3].

[1]: https://nodejs.org/api/buffer.html#class-blob
[2]: DefinitelyTyped#55311 (comment)
[3]: microsoft/dtslint#315
  • Loading branch information
alecgibson committed Jan 19, 2022
1 parent 3f78c2c commit cf2fc8d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
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
7 changes: 6 additions & 1 deletion types/superagent/tslint.json
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
{ "extends": "@definitelytyped/dtslint/dt.json" }
{
"extends": "@definitelytyped/dtslint/dt.json",
"rules": {
"no-outside-dependencies": false
}
}

0 comments on commit cf2fc8d

Please sign in to comment.