Skip to content

type RequestInfo should include URL #1016

Closed

Description

Currently RequestInfo is Request | string, but should (minimally) be Request | URL | string.

fetch(new URL('/some_api', 'https://example.com')) is valid, and works as you'd expect.

Technically it should be Request | { toString(): string } | string according to MDN, but I'm not sure if there are intricacies around that.

Activity

  1. Paril commented on Jun 5, 2021

    @Paril

    I think the intricacy for the latter is that it's not very type-safe and more error-prone, since everything will toString to something, but it's often not what you expect it to be unless it's a primitive. They use the same thing for dataset/css style values, as well as other writeables, even if the spec allows and/or encourages it (for instance writing to window.location can be done with a string, and is most commonly done as such, but currently it's only writeable with a URL)

  2. aslilac commented on Jun 6, 2021

    @aslilac
    Author

    Yeah, it feels like { toString(): string } falls into the same pit as {} in that almost anything could be cast to it.

  3. orta commented on Jun 28, 2021

    @orta
    Contributor

    Agree, I think we probably don't want this

  4. orta commented on Jun 28, 2021

    @orta
    Contributor

    Related: #1003

  5. dnalborczyk commented on Oct 19, 2021

    @dnalborczyk

    Agree, I think we probably don't want this

    Actually I would think we do want this.

    https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters

    A string or any other object with a stringifier — including a URL object — that provides the URL of the resource you want to fetch.

  6. dnalborczyk commented on Oct 19, 2021

    @dnalborczyk

    speaking of which, this is pretty much the same problem, but has been added:

    #331
    #332

  7. dnalborczyk commented on Oct 19, 2021

    @dnalborczyk

    as well as: #600

    fetch falls pretty much into the same category.

    similar: microsoft/TypeScript#43066

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions