Skip to content

Fetch options do not allow explicit undefined #1225

@chlonel

Description

@chlonel

Bug Description

It's hard to say for sure that this is a bug, but it feels like unintended behavior, so I'm reporting it as a bug.

Passing redirect: undefined as an option of fetch will throw an error.
At the time of executing the following code, init.redirect may be assigned undefined, which will be considered as an invalid value.
This does not only happen with redirect, but also with other options such as method and cache.

// 22. If init["redirect"] exists, then set request’s redirect mode to it.
if ('redirect' in init) {
  request.redirect = init.redirect
  if (!requestRedirect.includes(request.redirect)) {
    throw new TypeError(
      `Failed to construct 'Request': The provided value '${request.redirect}' is not a valid enum value of type RequestRedirect.`
    )
  }
}

Reproducible By

fetch("https://github.com", { redirect: undefined });
// TypeError: Failed to construct 'Request': The provided value 'undefined' is not a valid enum value of type RequestRedirect.

Expected Behavior

If undefined is passed, it will simply be ignored and the default value will be assigned.
Although undefined should not be passed by right, it is useful if it works as well, since Google Chrome and node-fetch implementations do not throw errors.

Environment

Manjaro 21.2.1
Node.js v16.13.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions