From a0c323d7b3202f093b2f3be088b9005e1f9fbe10 Mon Sep 17 00:00:00 2001 From: Julien Wajsberg Date: Wed, 4 Dec 2024 11:51:06 +0100 Subject: [PATCH] Fix the types for Link following recent preact type changes --- index.d.ts | 10 ++++++---- match/index.d.ts | 6 +++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/index.d.ts b/index.d.ts index d93ff2a..4f79d6f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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; +export function exec( + url: string, + route: string, + opts: { default?: boolean } +): false | Record; export function getCurrentUrl(): string; @@ -69,9 +73,7 @@ export function Route( props: RouteProps & Partial ): preact.VNode; -export function Link( - props: preact.JSX.HTMLAttributes -): preact.VNode; +export function Link(props: preact.JSX.IntrinsicElements['a']): preact.VNode; export function useRouter< RouteParams extends Record | null = Record< diff --git a/match/index.d.ts b/match/index.d.ts index d2627ae..565fee0 100644 --- a/match/index.d.ts +++ b/match/index.d.ts @@ -6,7 +6,11 @@ export class Match extends preact.Component { render(): preact.VNode; } -export interface LinkProps extends preact.JSX.HTMLAttributes { +// 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; }