From b726a1e60ff400b46629606002383e6864c77f29 Mon Sep 17 00:00:00 2001 From: billybimbob Date: Tue, 1 Nov 2022 02:10:26 -0500 Subject: [PATCH 1/2] update link and router types --- index.d.ts | 35 +++++++++++------------------------ match/index.d.ts | 7 ++++--- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/index.d.ts b/index.d.ts index 5c909e5..8ad494e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -22,11 +22,10 @@ export interface RoutableProps { default?: boolean; } +type DefaultParams = Record | null; + export interface RouterOnChangeArgs< - RouteParams extends Record | null = Record< - string, - string | undefined - > | null + RouteParams extends DefaultParams = DefaultParams > { router: Router; url: string; @@ -37,12 +36,8 @@ export interface RouterOnChangeArgs< matches: RouteParams; } -export interface RouterProps< - RouteParams extends Record | null = Record< - string, - string | undefined - > | null -> extends RoutableProps { +export interface RouterProps + extends RoutableProps { history?: CustomHistory; static?: boolean; url?: string; @@ -72,22 +67,14 @@ export function Route( props: RouteProps & Partial ): preact.VNode; -export function Link( - props: { activeClassName?: string } & preact.JSX.HTMLAttributes -): preact.VNode; +export interface LinkProps + extends Omit, 'onClick'> {} + +export function Link(props: LinkProps): preact.VNode; export function useRouter< - RouteParams extends Record | null = Record< - string, - string | undefined - > | null ->(): [ - RouterOnChangeArgs, - ( - urlOrOptions: string | { url: string; replace?: boolean }, - replace?: boolean - ) => boolean -]; + RouteParams extends DefaultParams = DefaultParams +>(): [RouterOnChangeArgs, typeof route]; declare module 'preact' { export interface Attributes extends RoutableProps {} diff --git a/match/index.d.ts b/match/index.d.ts index 13e617a..d9ea40a 100644 --- a/match/index.d.ts +++ b/match/index.d.ts @@ -1,14 +1,15 @@ import * as preact from 'preact'; -import { Link as StaticLink, RoutableProps } from '..'; +import { LinkProps as StaticLinkProps, RoutableProps } from '..'; export class Match extends preact.Component { render(): preact.VNode; } -export interface LinkProps extends preact.JSX.HTMLAttributes { +export interface LinkProps extends StaticLinkProps { + activeClass?: string; activeClassName?: string; - children?: preact.ComponentChildren; + path?: string; } export function Link(props: LinkProps): preact.VNode; From 943ba287a6128d138490bbcb7ce73ff603783bc3 Mon Sep 17 00:00:00 2001 From: billybimbob Date: Tue, 1 Nov 2022 02:10:52 -0500 Subject: [PATCH 2/2] fix type tests --- test/match.tsx | 7 +++++-- test/router.tsx | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/test/match.tsx b/test/match.tsx index d520646..f00da17 100644 --- a/test/match.tsx +++ b/test/match.tsx @@ -1,6 +1,5 @@ import { h } from 'preact'; -import { Link, RoutableProps } from '../'; -import { Match } from '../match'; +import { Match, Link } from '../match'; function ChildComponent({}: {}) { return
; @@ -11,6 +10,10 @@ function LinkComponent({}: {}) {
+ + This is some text + +
); } diff --git a/test/router.tsx b/test/router.tsx index 8f7542a..46d9a8f 100644 --- a/test/router.tsx +++ b/test/router.tsx @@ -1,5 +1,5 @@ -import { h, render, Component, FunctionalComponent } from 'preact'; -import Router, { Route, RoutableProps, useRouter } from '../'; +import { h, Component, FunctionalComponent } from 'preact'; +import Router, { Link, Route, useRouter } from '../'; class ClassComponent extends Component<{}, {}> { render() { @@ -11,6 +11,17 @@ const SomeFunctionalComponent: FunctionalComponent<{}> = ({}) => { return
; }; +function LinkComponent({}: {}) { + return ( +
+ + + This is some text + +
+ ); +} + function RouterWithComponents() { return (