mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
Make Route component extensible
Shouldn't have any impact whatsoever in existing codebases due to default generics
This commit is contained in:
Vendored
+1
-1
@@ -71,7 +71,7 @@ export interface RouteProps {
|
||||
exact?: boolean;
|
||||
strict?: boolean;
|
||||
}
|
||||
export class Route extends React.Component<RouteProps> { }
|
||||
export class Route<T extends RouteProps = RouteProps> extends React.Component<T> { }
|
||||
|
||||
export interface RouterProps {
|
||||
history: any;
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import * as React from 'react';
|
||||
import { Route, RouteProps } from 'react-router';
|
||||
|
||||
interface CustomRouteInterface extends RouteProps {
|
||||
aProperty: string;
|
||||
anotherOne: boolean;
|
||||
willItEnd?: number;
|
||||
}
|
||||
|
||||
// React advocates composition over inheritance, but doesn't prevent us from using it
|
||||
export default class CustomRoute extends Route<CustomRouteInterface> {
|
||||
render() {
|
||||
const maybeElement = super.render();
|
||||
return maybeElement && <div className="meaningfulClass">{React.cloneElement(maybeElement, this.props)}</div>;
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@
|
||||
"test/NavigateWithContext.tsx",
|
||||
"test/MemoryRouter.tsx",
|
||||
"test/Switch.tsx",
|
||||
"test/InheritingRoute.tsx",
|
||||
"test/WithRouter.tsx"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user