Skip to content

fix: request body type #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2021
Merged

fix: request body type #129

merged 2 commits into from
Jun 18, 2021

Conversation

achingbrain
Copy link
Member

@achingbrain achingbrain commented Jun 11, 2021

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 the RequestInit type to omit the original body type and include the new one.

Fixes this error:

node_modules/ipfs-utils/dist/src/types.d.ts:11:18 - error TS2430: Interface 'FetchOptions' incorrectly extends interface 'RequestInit'.
  Types of property 'body' are incompatible.
    Type 'Readable | BodyInit | null | undefined' is not assignable to type 'BodyInit | null | undefined'.
      Type 'Readable' is not assignable to type 'BodyInit | null | undefined'.
        Type 'Readable' is missing the following properties from type 'ReadableStream<Uint8Array>': locked, cancel, getReader, pipeThrough, and 2 more.

11 export interface FetchOptions extends RequestInit {
                    ~~~~~~~~~~~~


Found 1 error.

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.
@achingbrain achingbrain requested review from hugomrdias and Gozala June 11, 2021 17:25
@achingbrain
Copy link
Member Author

Refs: textileio/js-powergate-client#430

Copy link
Contributor

@Gozala Gozala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mode some suggestions, but works as is too

src/types.d.ts Outdated
export interface FetchOptions extends RequestInit {
type Modify<T, R> = Omit<T, keyof R> & R

export type FetchOptions = Modify<RequestInit, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think following would be more obvious.

export type FetchOptions = Override<RequestInit, { body?: ... }> & {
   ...
}

Co-authored-by: Irakli Gozalishvili <[email protected]>
@achingbrain achingbrain merged commit 1e8261a into master Jun 18, 2021
@achingbrain achingbrain deleted the fix/request-body-types branch June 18, 2021 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants