Skip to content

Commit

Permalink
fix: request body type (#129)
Browse files Browse the repository at this point in the history
Fixes two problems:

1. The import for `NodeReadableStream` was missing
2. We can't use `NodeReadableStream` as the type for `body` because it it not assignable
    to any type that makes up `BodyInit` so instead [modify](https://stackoverflow.com/questions/41285211/overriding-interface-property-type-defined-in-typescript-d-ts-file)
    the RequestInit type to omit the original `body` type and include the new one.

Co-authored-by: Irakli Gozalishvili <[email protected]>
  • Loading branch information
achingbrain and Gozala authored Jun 18, 2021
1 parent 7fe2ec9 commit 1e8261a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Readable as NodeReadableStream } from 'stream'

interface ProgressStatus {
total: number
loaded: number
Expand All @@ -6,7 +8,9 @@ interface ProgressStatus {

export interface ProgressFn { (status: ProgressStatus): void }

export interface FetchOptions extends RequestInit {
type Override<T, R> = Omit<T, keyof R> & R

export type FetchOptions = Override<RequestInit, {
/**
* Extended body with support for node readable stream
*/
Expand All @@ -29,7 +33,7 @@ export interface FetchOptions extends RequestInit {
*/
onDownloadProgress?: ProgressFn
overrideMimeType?: string
}
}>

export interface HTTPOptions extends FetchOptions {
json?: any
Expand Down

0 comments on commit 1e8261a

Please sign in to comment.