Skip to content

Commit

Permalink
Fix TypeScript error on URL class
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Sep 28, 2023
1 parent 2cccb5e commit 8edcf01
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions packages/runtime/src/polyfills/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export declare class URLSearchParams implements globalThis.URLSearchParams {
constructor(
init?: string[][] | Record<string, string> | string | URLSearchParams
);
/**
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/size)
*/
size: number;
/**
* Appends a specified key/value pair as a new search parameter.
Expand Down Expand Up @@ -158,20 +161,22 @@ URL.revokeObjectURL = (url) => {
objectUrls.delete(url);
};

// @ts-expect-error `inspect.custom` is not defined on URL class
URL.prototype[inspect.custom] = function (this: URL) {
return `URL ${inspect({
hash: this.hash,
host: this.host,
hostname: this.hostname,
href: this.href,
origin: this.origin,
password: this.password,
pathname: this.pathname,
port: this.port,
protocol: this.protocol,
search: this.search,
searchParams: this.searchParams,
username: this.username,
})}`;
};
Object.defineProperty(URL.prototype, inspect.custom, {
enumerable: false,
value(this: URL) {
return `URL ${inspect({
hash: this.hash,
host: this.host,
hostname: this.hostname,
href: this.href,
origin: this.origin,
password: this.password,
pathname: this.pathname,
port: this.port,
protocol: this.protocol,
search: this.search,
searchParams: this.searchParams,
username: this.username,
})}`;
},
});

0 comments on commit 8edcf01

Please sign in to comment.