Skip to content

Commit

Permalink
Fix the types for Link following recent preact type changes
Browse files Browse the repository at this point in the history
  • Loading branch information
julienw committed Dec 4, 2024
1 parent ee0ba49 commit a0c323d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 6 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import * as preact from 'preact';
export function route(url: string, replace?: boolean): boolean;
export function route(options: { url: string; replace?: boolean }): boolean;

export function exec(url: string, route: string, opts: { default?: boolean }): false | Record<string, string | undefined>;
export function exec(
url: string,
route: string,
opts: { default?: boolean }
): false | Record<string, string | undefined>;

export function getCurrentUrl(): string;

Expand Down Expand Up @@ -69,9 +73,7 @@ export function Route<Props>(
props: RouteProps<Props> & Partial<Props>
): preact.VNode;

export function Link(
props: preact.JSX.HTMLAttributes<HTMLAnchorElement>
): preact.VNode;
export function Link(props: preact.JSX.IntrinsicElements['a']): preact.VNode;

export function useRouter<
RouteParams extends Record<string, string | undefined> | null = Record<
Expand Down
6 changes: 5 additions & 1 deletion match/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ export class Match extends preact.Component<RoutableProps, {}> {
render(): preact.VNode;
}

export interface LinkProps extends preact.JSX.HTMLAttributes<HTMLAnchorElement> {
// Typescript doesn't allow to extends directly from an expression (see
// https://github.com/microsoft/TypeScript/issues/31843). Assigning to a
// separate type first makes it work.
type AnchorElement = preact.JSX.IntrinsicElements['a'];
export interface LinkProps extends AnchorElement {
activeClassName?: string;
children?: preact.ComponentChildren;
}
Expand Down

0 comments on commit a0c323d

Please sign in to comment.