Skip to content

Commit 9c7ef36

Browse files
committed
Work around URLPattern polyfill type issues
1 parent 5ab62ff commit 9c7ef36

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// We use a custom type definition for this due to https://github.com/kenchris/urlpattern-polyfill/issues/135.
2+
// Without this, this conflicts with the v24 Node.js type definitions. This would still cause big problems if
3+
// we expose URLPattern in any of our own APIs & type definitions, but fortunately we don't (at time of writing)
4+
5+
export type URLPatternInput = URLPatternInit | string;
6+
7+
export declare class URLPattern {
8+
constructor(init?: URLPatternInput, baseURL?: string);
9+
10+
test(input?: URLPatternInput, baseURL?: string): boolean;
11+
12+
exec(input?: URLPatternInput, baseURL?: string): URLPatternResult | null;
13+
14+
readonly protocol: string;
15+
readonly username: string;
16+
readonly password: string;
17+
readonly hostname: string;
18+
readonly port: string;
19+
readonly pathname: string;
20+
readonly search: string;
21+
readonly hash: string;
22+
}
23+
24+
interface URLPatternInit {
25+
baseURL?: string;
26+
username?: string;
27+
password?: string;
28+
protocol?: string;
29+
hostname?: string;
30+
port?: string;
31+
pathname?: string;
32+
search?: string;
33+
hash?: string;
34+
}
35+
36+
export interface URLPatternResult {
37+
inputs: [URLPatternInput];
38+
protocol: URLPatternComponentResult;
39+
username: URLPatternComponentResult;
40+
password: URLPatternComponentResult;
41+
hostname: URLPatternComponentResult;
42+
port: URLPatternComponentResult;
43+
pathname: URLPatternComponentResult;
44+
search: URLPatternComponentResult;
45+
hash: URLPatternComponentResult;
46+
}
47+
48+
export interface URLPatternComponentResult {
49+
input: string;
50+
groups: {
51+
[key: string]: string | undefined;
52+
};
53+
}

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"paths": {
1414
"https-proxy-agent": ["./custom-typings/proxy-agent-modules.d.ts"],
1515
"socks-proxy-agent": ["./custom-typings/proxy-agent-modules.d.ts"],
16-
"pac-proxy-agent": ["./custom-typings/proxy-agent-modules.d.ts"]
16+
"pac-proxy-agent": ["./custom-typings/proxy-agent-modules.d.ts"],
17+
"urlpattern-polyfill": ["./custom-typings/urlpattern-polyfill.d.ts"],
1718
}
1819
},
1920
"compileOnSave": true,

0 commit comments

Comments
 (0)