Skip to content

Commit

Permalink
Fix type problem with URL and URLSearchParams globals (#969)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmmmwh authored and sindresorhus committed Dec 7, 2019
1 parent b962d08 commit 2d5e28d
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions source/utils/types.ts
Expand Up @@ -247,3 +247,44 @@ export interface CancelableRequest<T extends Response | Response['body']> extend
buffer(): CancelableRequest<Buffer>;
text(): CancelableRequest<string>;
}

// TODO: Remove this when https://github.com/DefinitelyTyped/DefinitelyTyped/issues/34960 is resolved
declare global {
// @ts-ignore TypeScript complains about duplicated identifier.
class URL {
readonly origin: string;
readonly searchParams: URLSearchParams;
hash: string;
host: string;
hostname: string;
href: string;
password: string;
pathname: string;
port: string;
protocol: string;
search: string;
username: string;

constructor(input: string, base?: string | URL);
toString(): string;
toJSON(): string;
}

// @ts-ignore TypeScript complains about duplicated identifier.
class URLSearchParams implements Iterable<[string, string]> {
constructor(init?: URLSearchParams | string | {[key: string]: string | string[] | undefined} | Iterable<[string, string]> | Array<[string, string]>);
append(name: string, value: string): void;
delete(name: string): void;
entries(): IterableIterator<[string, string]>;
forEach(callback: (value: string, name: string, searchParams: this) => void): void;
get(name: string): string | null;
getAll(name: string): string[];
has(name: string): boolean;
keys(): IterableIterator<string>;
set(name: string, value: string): void;
sort(): void;
toString(): string;
values(): IterableIterator<string>;
[Symbol.iterator](): IterableIterator<[string, string]>;
}
}

0 comments on commit 2d5e28d

Please sign in to comment.