Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#57641 [superagent] remove dom typings by @…
Browse files Browse the repository at this point in the history
…alecgibson

* [superagent] remove `dom` typings

At the moment, the `@types/superagent` library silently includes `dom`
typings, even in Node-only projects. This is *very* surprising.

This change sets the problematic `Response.xhr` property to `any`.

The `xhr` property is for [browser-only use][1], so it doesn't really
make sense for this browser-only property to exist on `Response`,
which currently [extends a `NodeJS.ReadableStream`][2], where you would
never expect access to DOM types.

[1]: https://github.com/visionmedia/superagent/blob/048cf185d954028b1dccde0717d2488b2284c297/src/client.js#L88
[2]: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/59b04cbc8e5570ca2b8717e1cb054cfbbea01e01/types/superagent/index.d.ts#L103

* Apply suggestions from code review

Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) <peterblazejewicz@users.noreply.github.com>

Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) <peterblazejewicz@users.noreply.github.com>
  • Loading branch information
2 people authored and Martin Badin committed Feb 23, 2022
1 parent a2ee9a6 commit 72763e5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
3 changes: 1 addition & 2 deletions types/superagent/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// TypeScript Version: 3.0

/// <reference types="node" />
/// <reference lib="dom" />

import * as fs from "fs";
import * as http from "http";
Expand Down Expand Up @@ -127,7 +126,7 @@ declare namespace request {
text: string;
type: string;
unauthorized: boolean;
xhr: XMLHttpRequest;
xhr: any;
redirects: string[];
}

Expand Down
6 changes: 3 additions & 3 deletions types/superagent/superagent-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ request.get("http://example.com/search").retry(2, callback).end(callback);
})();

// Attaching files
const blob: Blob = new File([], "thor.png");
declare const blob: Blob;
request
.post("/upload")
.attach("avatar", "path/to/tobi.png", "user.png")
Expand Down Expand Up @@ -282,8 +282,8 @@ request
.get("/blob")
.responseType("blob")
.end((err, res) => {
assert(res.xhr instanceof XMLHttpRequest);
assert(res.xhr.response instanceof Blob);
res.xhr; // $ExpectType any
res.xhr.response; // $ExpectType any
});

// HTTPS request, from: https://github.com/visionmedia/superagent/commit/6158efbf42cb93d77c1a70887284be783dd7dabe
Expand Down
3 changes: 1 addition & 2 deletions types/superagent/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
Expand Down

0 comments on commit 72763e5

Please sign in to comment.