Skip to content

Improve type safety of URLPattern args #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type * as Types from "./types.js";

declare global {
class URLPattern extends Types.URLPattern {}
type URLPatternArgs = Types.URLPatternArgs;
type URLPatternInit = Types.URLPatternInit;
type URLPatternResult = Types.URLPatternResult;
type URLPatternComponentResult = Types.URLPatternComponentResult;
Expand Down
20 changes: 10 additions & 10 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export type URLPatternInput = URLPatternInit | string;
export type URLPatternArgs =
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we keep the name URLPatternInput to follow the spec?

| [URLPatternInit | RegExp | undefined]
| [string, string | undefined];

export declare class URLPattern {
constructor(init?: URLPatternInput, baseURL?: string);

test(input?: URLPatternInput, baseURL?: string): boolean;

exec(input?: URLPatternInput, baseURL?: string): URLPatternResult | null;
constructor(...args: URLPatternArgs);
test(...args: URLPatternArgs): boolean;
exec(...args: URLPatternArgs): URLPatternResult | null;

readonly protocol: string;
readonly username: string;
Expand All @@ -17,20 +17,20 @@ export declare class URLPattern {
readonly hash: string;
}

interface URLPatternInit {
baseURL?: string;
export interface URLPatternInit {
protocol?: string;
username?: string;
password?: string;
protocol?: string;
hostname?: string;
port?: string;
pathname?: string;
search?: string;
hash?: string;
baseURL?: string;
}

export interface URLPatternResult {
inputs: [URLPatternInput];
inputs: URLPatternArgs;
protocol: URLPatternComponentResult;
username: URLPatternComponentResult;
password: URLPatternComponentResult;
Expand Down