Skip to content

Commit f5328e9

Browse files
committed
chore: remove native-fetch retyping
These types are incorrect and cause errors in other modules. Fixes #109
1 parent d42bd36 commit f5328e9

File tree

6 files changed

+10
-129
lines changed

6 files changed

+10
-129
lines changed

src/http.js

+2-7
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' })

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/native-fetch/index.d.ts

-117
This file was deleted.

0 commit comments

Comments
 (0)