mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
Merge pull request #15314 from donaldpipowitch/patch-4
fixed match interface in react-router v4
This commit is contained in:
2
react-router-dom/index.d.ts
vendored
2
react-router-dom/index.d.ts
vendored
@@ -10,7 +10,6 @@ declare module 'react-router-dom' {
|
||||
MemoryRouter,
|
||||
Redirect,
|
||||
RouteComponentProps,
|
||||
PartialRouteComponentProps,
|
||||
RouteProps,
|
||||
Route,
|
||||
Router,
|
||||
@@ -68,7 +67,6 @@ declare module 'react-router-dom' {
|
||||
MemoryRouter,
|
||||
Redirect,
|
||||
RouteComponentProps, // TypeScript specific, not from React Router itself
|
||||
PartialRouteComponentProps, // TypeScript specific, not from React Router itself
|
||||
RouteProps, // TypeScript specific, not from React Router itself
|
||||
Route,
|
||||
Router,
|
||||
|
||||
14
react-router/index.d.ts
vendored
14
react-router/index.d.ts
vendored
@@ -48,12 +48,9 @@ declare module 'react-router' {
|
||||
history: H.History;
|
||||
}
|
||||
|
||||
interface PartialRouteComponentProps<P> extends Partial<RouteComponentProps<P>> {
|
||||
}
|
||||
|
||||
interface RouteProps {
|
||||
location?: H.Location;
|
||||
component?: React.SFC<PartialRouteComponentProps<any> | void> | React.ComponentClass<PartialRouteComponentProps<any> | void>;
|
||||
component?: React.SFC<RouteComponentProps<any> | void> | React.ComponentClass<RouteComponentProps<any> | void>;
|
||||
render?: (props: RouteComponentProps<any>) => React.ReactNode;
|
||||
children?: (props: RouteComponentProps<any>) => React.ReactNode | React.ReactNode;
|
||||
path?: string;
|
||||
@@ -84,13 +81,13 @@ declare module 'react-router' {
|
||||
|
||||
interface match<P> {
|
||||
params: P;
|
||||
isExact?: boolean;
|
||||
path?: string;
|
||||
url?: string;
|
||||
isExact: boolean;
|
||||
path: string;
|
||||
url: string;
|
||||
}
|
||||
|
||||
|
||||
function matchPath<P>(pathname: string, props: RouteProps): match<P>;
|
||||
function matchPath<P>(pathname: string, props: RouteProps): match<P> | null;
|
||||
|
||||
|
||||
function withRouter(component: React.SFC<RouteComponentProps<any>> | React.ComponentClass<RouteComponentProps<any>>): React.ComponentClass<any>;
|
||||
@@ -101,7 +98,6 @@ declare module 'react-router' {
|
||||
Prompt,
|
||||
Redirect,
|
||||
RouteComponentProps, // TypeScript specific, not from React Router itself
|
||||
PartialRouteComponentProps, // TypeScript specific, not from React Router itself
|
||||
RouteProps, // TypeScript specific, not from React Router itself
|
||||
Route,
|
||||
Router,
|
||||
|
||||
@@ -23,11 +23,18 @@ const RecursiveExample = () => (
|
||||
</Router>
|
||||
)
|
||||
|
||||
interface PersonProps extends Partial<RouteComponentProps<{id: number}>> {
|
||||
match: match<{id: number}>;
|
||||
interface InitialPersonProps {
|
||||
match: {
|
||||
params: {
|
||||
id: number;
|
||||
};
|
||||
url: string;
|
||||
};
|
||||
}
|
||||
|
||||
const Person: React.SFC<PersonProps> = ({ match }) => {
|
||||
type PersonProps = RouteComponentProps<{ id: number }>;
|
||||
|
||||
const Person: React.SFC<InitialPersonProps | PersonProps> = ({ match }) => {
|
||||
const person = find(match.params.id)
|
||||
|
||||
return (
|
||||
@@ -42,9 +49,9 @@ const Person: React.SFC<PersonProps> = ({ match }) => {
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<Route path={`${match.url}/:id`} component={Person}/>
|
||||
<Route path={`${match.url}/:id`} component={Person as React.SFC<PersonProps>}/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default RecursiveExample
|
||||
export default RecursiveExample
|
||||
|
||||
Reference in New Issue
Block a user