Skip to content

Commit dab0aef

Browse files
alecgibsonMartin Badin
authored andcommitted
[superagent] Fix Blob error (DefinitelyTyped#58312)
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
1 parent 37e33d8 commit dab0aef

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

types/superagent/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import * as fs from "fs";
2020
import * as http from "http";
2121
import * as stream from "stream";
2222
import * as cookiejar from "cookiejar";
23+
import { Blob } from "buffer";
2324

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

types/superagent/superagent-tests.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import request = require("superagent");
33
import * as fs from "fs";
44
import assert = require("assert");
55
import { Agent } from "https";
6+
import { Blob } from "buffer";
67

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

221222
// Attaching files
222-
declare const blob: Blob;
223+
const blob = new Blob([]);
223224
request
224225
.post("/upload")
225226
.attach("avatar", "path/to/tobi.png", "user.png")

types/superagent/tslint.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
{ "extends": "@definitelytyped/dtslint/dt.json" }
1+
{
2+
"extends": "@definitelytyped/dtslint/dt.json",
3+
"rules": {
4+
"no-outside-dependencies": false
5+
}
6+
}

0 commit comments

Comments
 (0)