Skip to content

Commit f6406c5

Browse files
authored
fix: remove retyping of modules with types (#125)
The types are incorrect and cause errors with modules that check the types of their deps. Types for `is-electron` can be removed once cheton/is-electron#7 is resolved. Fixes #109 BREAKING CHANGE: `ResponseWithURL` type is not exported any more as it uses a private name and causes an inconsistency between node and the browser
1 parent ca301b0 commit f6406c5

File tree

8 files changed

+10
-252
lines changed

8 files changed

+10
-252
lines changed

src/http.js

+2-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { AbortController } = require('native-abort-controller')
99
const anySignal = require('any-signal')
1010

1111
/**
12-
* @typedef {import('native-fetch').Response} Response
12+
* @typedef {import('./types').ExtendedResponse} ExtendedResponse
1313
* @typedef {import('stream').Readable} NodeReadableStream
1414
* @typedef {import('stream').Duplex} NodeDuplexStream
1515
* @typedef {import('./types').HTTPOptions} HTTPOptions
@@ -88,7 +88,7 @@ class HTTP {
8888
*
8989
* @param {string | Request} resource
9090
* @param {HTTPOptions} options
91-
* @returns {Promise<Response>}
91+
* @returns {Promise<ExtendedResponse>}
9292
*/
9393
async fetch (resource, options = {}) {
9494
/** @type {HTTPOptions} */
@@ -168,7 +168,6 @@ class HTTP {
168168
/**
169169
* @param {string | Request} resource
170170
* @param {HTTPOptions} options
171-
* @returns {Promise<Response>}
172171
*/
173172
post (resource, options = {}) {
174173
return this.fetch(resource, { ...options, method: 'POST' })
@@ -177,7 +176,6 @@ class HTTP {
177176
/**
178177
* @param {string | Request} resource
179178
* @param {HTTPOptions} options
180-
* @returns {Promise<Response>}
181179
*/
182180
get (resource, options = {}) {
183181
return this.fetch(resource, { ...options, method: 'GET' })
@@ -186,7 +184,6 @@ class HTTP {
186184
/**
187185
* @param {string | Request} resource
188186
* @param {HTTPOptions} options
189-
* @returns {Promise<Response>}
190187
*/
191188
put (resource, options = {}) {
192189
return this.fetch(resource, { ...options, method: 'PUT' })
@@ -195,7 +192,6 @@ class HTTP {
195192
/**
196193
* @param {string | Request} resource
197194
* @param {HTTPOptions} options
198-
* @returns {Promise<Response>}
199195
*/
200196
delete (resource, options = {}) {
201197
return this.fetch(resource, { ...options, method: 'DELETE' })
@@ -204,7 +200,6 @@ class HTTP {
204200
/**
205201
* @param {string | Request} resource
206202
* @param {HTTPOptions} options
207-
* @returns {Promise<Response>}
208203
*/
209204
options (resource, options = {}) {
210205
return this.fetch(resource, { ...options, method: 'OPTIONS' })
@@ -335,35 +330,30 @@ HTTP.streamToAsyncIterator = fromStream
335330
/**
336331
* @param {string | Request} resource
337332
* @param {HTTPOptions} [options]
338-
* @returns {Promise<Response>}
339333
*/
340334
HTTP.post = (resource, options) => new HTTP(options).post(resource, options)
341335

342336
/**
343337
* @param {string | Request} resource
344338
* @param {HTTPOptions} [options]
345-
* @returns {Promise<Response>}
346339
*/
347340
HTTP.get = (resource, options) => new HTTP(options).get(resource, options)
348341

349342
/**
350343
* @param {string | Request} resource
351344
* @param {HTTPOptions} [options]
352-
* @returns {Promise<Response>}
353345
*/
354346
HTTP.put = (resource, options) => new HTTP(options).put(resource, options)
355347

356348
/**
357349
* @param {string | Request} resource
358350
* @param {HTTPOptions} [options]
359-
* @returns {Promise<Response>}
360351
*/
361352
HTTP.delete = (resource, options) => new HTTP(options).delete(resource, options)
362353

363354
/**
364355
* @param {string | Request} resource
365356
* @param {HTTPOptions} [options]
366-
* @returns {Promise<Response>}
367357
*/
368358
HTTP.options = (resource, options) => new HTTP(options).options(resource, options)
369359

src/http/error.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ exports.AbortError = AbortError
1818

1919
class HTTPError extends Error {
2020
/**
21-
* @param {import('native-fetch').Response} response
21+
* @param {Response} response
2222
*/
2323
constructor (response) {
2424
super(response.statusText)

src/http/fetch.browser.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,5 @@ class ResponseWithURL extends Response {
136136
module.exports = {
137137
fetch: fetchWith,
138138
Request,
139-
Headers,
140-
ResponseWithURL
139+
Headers
141140
}

src/http/fetch.node.js

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const { Request, Response, Headers, default: nativeFetch } = require('../fetch')
55
const toStream = require('it-to-stream')
66
const { Buffer } = require('buffer')
77
/**
8-
* @typedef {import('native-fetch').BodyInit} BodyInit
98
* @typedef {import('stream').Readable} NodeReadableStream
109
*
1110
* @typedef {import('../types').FetchOptions} FetchOptions

src/types.d.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { RequestInit, Response } from '../types/native-fetch'
21
interface ProgressStatus {
32
total: number
43
loaded: number
@@ -51,3 +50,9 @@ export interface HTTPOptions extends FetchOptions {
5150
*/
5251
handleError?: (rsp: Response) => Promise<void>
5352
}
53+
54+
export interface ExtendedResponse extends Response {
55+
iterator: () => AsyncGenerator<Uint8Array, void, undefined>
56+
57+
ndjson: () => AsyncGenerator<any, void, undefined>
58+
}

types/electron-fetch/index.d.ts

-117
This file was deleted.

types/iso-url/index.d.ts

-1
This file was deleted.

types/native-fetch/index.d.ts

-117
This file was deleted.

0 commit comments

Comments
 (0)