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; 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 (