Skip to content

Commit

Permalink
fix: Fix typing for redirects (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
taion committed Jan 17, 2019
1 parent 4adabac commit 6f6df34
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,14 @@ declare module 'found' {

interface RedirectProps {
from: string;
to: string;
to: string | ((match: Match) => LocationDescriptor);
}

class Redirect extends React.Component<RedirectProps> {}

interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
Component?: React.ComponentType<any>;
to: string | LocationDescriptor;
to: LocationDescriptor;
// match: Match, provided by withRouter
activeClassName?: string;
activeStyle?: any;
Expand All @@ -368,7 +368,7 @@ declare module 'found' {
): React.ComponentType<Omit<Props, keyof WithRouter>>;

class RedirectException {
constructor(location: string | LocationDescriptor);
constructor(location: LocationDescriptor);
}

/**
Expand Down
11 changes: 7 additions & 4 deletions types/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
import * as React from 'react';

import {
createBrowserRouter,
createConnectedRouter,
createRender,
createBrowserRouter,
makeRouteConfig,
Route,
resolver,
HttpError,
Match,
Redirect,
resolver,
Route,
} from 'found';

// Just test that these imports work.
import _1 from 'found/lib/HttpError';
import _2 from 'found/lib/RedirectException';
import _3 from 'found/lib/makeRouteConfig';
Expand Down Expand Up @@ -68,6 +69,8 @@ const routeConfig = makeRouteConfig(
<Route path="/" Component={Component} />
<Route path="/foo/:id" getComponent={() => Promise.resolve(Component2)} />
<Route path="/bar/:id" getComponent={() => Component2} />
<Redirect from="/baz" to="/foo" />
<Redirect from="/quz" to={() => ({ pathname: '/foo', other: 9 })} />
</Route>,
);

Expand Down

0 comments on commit 6f6df34

Please sign in to comment.