Skip to content

Help: How do I make history.pushState() accept an URL instance? #670

Closed
@Kocal

Description

@Kocal

Hi,

I opened this PR (microsoft/TypeScript#30512) to make the following code compilable with TypeScript:

const url = new URL(location.href)
url.search = '?foo=bar'
history.pushState({}, 'Title', url)

The following code is working, (you can try it in your console, it will append ?foo=bar to the URL), but we can't compile it with TypeScript:
Sélection_026

The current signature is

replaceState(data: any, title: string, url?: string | null): void;

and I want to update it to:

replaceState(data: any, title: string, url?: string | URL | null): void;

So as @typescript-bot said (microsoft/TypeScript#30512 (comment)), I should open a PR here but I don't know what to update.

After some research, replaceState appears three times in the following files:

  • dom.generated.d.ts, but I should not update this file manually because it's auto-generated
  • browser.webidl.preprocessed.json, I should not update it either
  • HTML - Session history and navigation.widl, but the signature is void replaceState(any data, DOMString title, optional USVString? url = null) and I don't understand how optional USVString? url = null is transformed to url?: string | null 🤔

Even in the overridingTypes.json file, I don't see any pushState() / replaceState() 😕

So what should I do to make replaceState() and pushState() accepts an URL instance as the 3rd parameter?

Thanks! :)

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