Skip to content
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

RequestInit interface does not support all of the props in dom RequestInit interface #1172

Closed
btakita opened this issue Jan 23, 2022 · 2 comments · Fixed by suneettipirneni/undici#1 or #1199
Labels
bug Something isn't working

Comments

@btakita
Copy link

btakita commented Jan 23, 2022

Bug Description

The RequestInit interface does not have many of the props in the dom version of RequestInit.

undici RequestInit

undici/types/fetch.d.ts

Lines 95 to 103 in 5d52423

export interface RequestInit {
readonly method?: string
readonly keepalive?: boolean
readonly headers?: HeadersInit
readonly body?: BodyInit
readonly redirect?: RequestRedirect
readonly integrity?: string
readonly signal?: AbortSignal
}

dom RequestInit

interface RequestInit {
    /** A BodyInit object or null to set request's body. */
    body?: BodyInit | null;
    /** A string indicating how the request will interact with the browser's cache to set request's cache. */
    cache?: RequestCache;
    /** A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's credentials. */
    credentials?: RequestCredentials;
    /** A Headers object, an object literal, or an array of two-item arrays to set request's headers. */
    headers?: HeadersInit;
    /** A cryptographic hash of the resource to be fetched by request. Sets request's integrity. */
    integrity?: string;
    /** A boolean to set request's keepalive. */
    keepalive?: boolean;
    /** A string to set request's method. */
    method?: string;
    /** A string to indicate whether the request will use CORS, or will be restricted to same-origin URLs. Sets request's mode. */
    mode?: RequestMode;
    /** A string indicating whether request follows redirects, results in an error upon encountering a redirect, or returns the redirect (in an opaque fashion). Sets request's redirect. */
    redirect?: RequestRedirect;
    /** A string whose value is a same-origin URL, "about:client", or the empty string, to set request's referrer. */
    referrer?: string;
    /** A referrer policy to set request's referrerPolicy. */
    referrerPolicy?: ReferrerPolicy;
    /** An AbortSignal to set request's signal. */
    signal?: AbortSignal | null;
    /** Can only be null. Used to disassociate request from any Window. */
    window?: null;
}

Reproducible By

fetch('https://example.com', { mode: 'cors' })

Expected Behavior

No type errors

Logs & Screenshots

TS2345: Argument of type '{ mode: string; }' is not assignable to parameter of type 'RequestInit'.
  Object literal may only specify known properties, and 'mode' does not exist in type 'RequestInit'.

Environment

Node v17.3.1

Additional context

Even if the props are not implemented, it is still useful to have them to properly support isomorphic fetch.

@btakita btakita added the bug Something isn't working label Jan 23, 2022
@ronag
Copy link
Member

ronag commented Jan 23, 2022

Seems like a bug in the typescript definitions. pR welcome.

@jimsimon
Copy link
Contributor

I believe some of the subtypes don't match either (e.g. BodyInit and HeadersInit).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants