Skip to content
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

Fix the types for Link following recent preact type changes #474

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Fix the types for Link following recent preact type changes
julienw committed Dec 4, 2024
commit a0c323d7b3202f093b2f3be088b9005e1f9fbe10
10 changes: 6 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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;

@@ -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<
6 changes: 5 additions & 1 deletion match/index.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}

Unchanged files with check annotations Beta

let onChange = jasmine.createSpy();
mount(
<div>
<div dangerouslySetInnerHTML={{ __html: `<a href="#foo">foo</a>` }} />

Check warning on line 108 in test/dom.test.js

GitHub Actions / build_test

Dangerous property 'dangerouslySetInnerHTML' found
<Router onChange={onChange}>
<div default />
</Router>